Contentful Migration Scripts: Automate Your Data Move
Automate your content extraction, transformation, and load into Directus. No manual copy-paste. No data loss. Repeatable. Testable.
Scripted migrations are repeatable, testable, and reversible
Automate field mappings, handle locales at scale, and roll back if needed. This is how teams move millions of records safely.
Your Migration: 5 Technical Steps
From Contentful API to Directus, step by step.
Plan and Audit Your Content
Export Contentful spaces, count records, identify custom fields, map locales. Document any webhooks or workflows that depend on Contentful.
Extract from Contentful API
Write a script using Contentful's Management API to pull content models, entries, and assets. Use the contentful-migration tool or a Node.js client library.
Transform Data for Directus
Map Contentful field types to Directus types. Handle linked entries as foreign keys. Flatten nested references. Preserve locale data in translation tables.
Load into Directus
Push data via Directus REST or GraphQL API. Use batch operations to handle large volumes. Test in a staging environment first.
Verify and Cutover
Validate record counts, test queries, check locales. Once confirmed, update DNS or API endpoints. Keep Contentful as a fallback until day 2.
What the Contentful Migration Tool Does
Contentful's open-source migration library (github.com/contentful/contentful-migration, 344 stars, 1,232 commits) handles model and entry transformations programmatically.
It lets you:
- Create or edit content types and fields
- Transform existing entries (batch updates, field renames, type conversions)
- Derive linked entries and cross-references
- Retry failed operations automatically
- Chain operations in a declarative, reproducible format
When to script vs. when to hire help
DIY script migration works best if:
- Your data is less than 500K records
- Content model is relatively flat (few nested references)
- You have 1-2 team members who can code Node.js or Python
- You have 3-5 days to work on it
Consider a professional migration service if:
- You have 1M+ records with complex nested structures
- You rely heavily on Contentful-specific workflows or custom apps
- Your data has edge cases or legacy inconsistencies
- Downtime costs are high (ecommerce, live platforms)
- You need it done in less than 2 days
Contentful to Directus: Field Mapping and Query Syntax
Field Types: Direct Mapping
Most Contentful field types map 1:1 to Directus:
| Contentful | Directus | Notes |
|---|---|---|
| Text | String | Single line text |
| Long text | Text | Multi-line paragraph |
| Number | Integer or Decimal | Preserve decimal flag |
| Boolean | Boolean | True/false |
| Date & time | DateTime | Include timezone |
| Location | Geometry (Point) | Convert lat/lng to GeoJSON |
| JSON | JSON | Pass through unchanged |
| Reference | Many-to-one or Many-to-many | Link to other collections |
| Symbols | Tags relation or JSON array | Depends on use case |
Linked Entries: From References to Foreign Keys
Contentful (REST API):
Entry with linked author reference stored as nested object with sys.id.
Directus equivalent:
Simple foreign key field: author_id = "author-123". In your transform script, extract the sys.id and map it directly.
Locales: Translation Tables
Contentful approach: One entry document per language, linked by contentId.
Directus approach: One record in the main collection plus rows in a translations table. Set default language in Directus settings. Store translations in directus_translations or a custom table. Query with ?filter[language_code][eq]=fr to fetch French content.
Query Syntax: REST and GraphQL
Contentful REST:
GET /spaces/{space}/environments/{env}/entries?content_type=blog-post&limit=100
Directus REST:
GET /items/blog_posts?limit=100&fields[]=.
Directus GraphQL:
Query blog_posts with nested relationships and translations automatically included.
Migration Script Patterns: Extract, Transform, Load
1. Extract from Contentful Management API
Use the contentful npm package or contentful-migration CLI to pull your space. Authenticate with management token. Fetch all entries, content types, and assets. Save to JSON for processing.
Key pattern: Batch requests to respect API rate limits. Contentful free tier allows ~1 request/second. Enterprise plans go higher but you'll still hit limits on large migrations.
2. Transform: Map Fields and Locales
Loop through Contentful entries and build Directus-compatible objects. For each Contentful field:
- Extract the locale value (Contentful stores fields as {"en-US": value, "fr-FR": value})
- Map to Directus field type
- Create translation records for non-default locales
Handle linked entries by extracting the sys.id and creating a foreign key. If you have many-to-many relationships, create a junction table and populate it during transform.
3. Load into Directus
Use Directus REST API (/items/collection_name) or GraphQL mutations. Push data in batches to avoid timeouts (typically 100-500 records per request). Include retry logic for transient failures.
Pattern: Check total record count before and after. If Directus count matches Contentful count, migration succeeded. Log failures for manual review.
4. Validate Counts and Spot-Check Data
After loading, verify:
- Record count matches source
- Locales appear in translation tables
- Foreign keys are not null for required references
- Asset URLs resolve
Spot-check 5-10 entries by hand. Query via GraphQL to ensure relationships render correctly.
Why Managed Directus Hosting?
After you migrate, your infrastructure should not be a distraction.
Predictable Pricing, No Surprises
Contentful charges per API call. Directus is flat-rate. Opsily's managed hosting starts at $15/month with all features included. No overage bills when your traffic grows. Scale from small projects to millions of requests.
Your Data, Your Infrastructure
Directus runs on your database or ours. Opsily deploys to EU data centers, so your content stays compliant with GDPR. You own the data from day one. Export anytime. No vendor lock-in.
Automatic Backups and Scaling
We handle nightly encrypted backups, SSL certificates, security patching, and scaling. You focus on content and APIs, not ops. Directus runs on reliable infrastructure with 99.9% uptime.
Built for teams who need reliability
Directus Managed Hosting Plans
All plans include GDPR-compliant EU data centers, automatic backups, and SSL. Upgrade anytime.
Loading pricing...
Enterprise Trust, Built In
Run your Contentful migration on infrastructure you can rely on.
GDPR Compliant
Your data is stored in the EU and managed according to GDPR regulations. Full data residency compliance for content at scale.
Data Sovereignty
You own your database. Directus is source-available (MSCL license). No vendor lock-in, no surprise migrations or policy changes.
European Data Centers
Your data runs on secure infrastructure in the EU, ensuring full data residency compliance with GDPR and data sovereignty regulations.
No Vendor Lock-In
Export your data anytime. Directus works with any SQL database. Full portability to another hosting provider.
Technical Migration FAQs
Answers to common questions about scripting your Contentful migration.
Timeline depends on your data size. Small migrations (under 100K records, simple schemas) take 1-2 business days. Medium (100K-1M records, complex relationships, multiple locales) takes 3-5 days. Large migrations (1M+ records, custom integrations, compliance checks) take 5-9 business days. Professional services from ClonePartner or FocusReactive accelerate large projects.
Ready to Move Your Content?
Start with the migration script patterns above. Run them locally against your Contentful space. Once you are confident, Opsily handles the managed hosting.