
Describe and execute changes to your content model and transform entry content.
What is Contentful?
Contentful provides content infrastructure for digital teams to power websites, apps, and devices. Unlike a CMS, Contentful was built to integrate with the modern software stack. It offers a central hub for structured content, powerful management and delivery APIs, and a customizable web app that enable developers and content creators to ship their products faster.
Table of contents
migrationcreateContentType(id[, opts]) : ContentTypeeditContentType(id[, opts]) : ContentTypedeleteContentType(id)transformEntries(config)
deriveLinkedEntries(config)
transformEntriesToType(config)
createTag(id[, opts, visibility])editTag(id[, opts])deleteTag(id)setTagsForEntries(config)
contextmakeRequest(config)spaceId : stringaccessToken : stringcreateField(id[, opts]) : FieldeditField(id[, opts]) : FielddeleteField(id) : voidchangeFieldId (currentId, newId) : voidmoveField (id) : MovableFieldchangeFieldControl (fieldId, widgetNamespace, widgetId[, settings]) : voidresetFieldControl (fieldId) : voidcopyFieldControl (sourceFieldId, destinationFieldId) : voidaddSidebarWidget (widgetNamespace, widgetId[, settings, insertBeforeWidgetId]) : voidupdateSidebarWidget (widgetNamespace, widgetId, settings) : voidremoveSidebarWidget (widgetNamespace, widgetId) : voidresetSidebarToDefault () : voidconfigureEntryEditor (widgetNamespace, widgetId[, settings]) : voidconfigureEntryEditors (EntryEditor[]) : voidresetEntryEditorToDefault () : voidcreateEditorLayout () : EditorLayouteditEditorLayout () : EditorLayoutdeleteEditorLayout () : voidsetAnnotations(AnnotationId[])clearAnnotations()addTaxonomyValidation(id, linkType[, opts])clearTaxonomyValidations()setTaxonomyValidations(validations)setAnnotations(AnnotationId[])clearAnnotations()moveField(id) : MovableEditorLayoutItemcreateFieldGroup(id[, opts]) : EditorLayoutFieldGroupdeleteFieldGroup (id) : voidchangeFieldGroupId (currentId, newId)editFieldGroup (id[, opts]) : EditorLayoutFieldGroupcreateFieldGroup (id[, opts]) : EditorLayoutFieldGroupchangeFieldGroupControl (id, widgetNamespace, widgetId[, settings]) : voidnpm install contentful-migration
We moved the CLI version of this tool into our Contentful CLI. This allows our users to use and install only one single CLI tool to get the full Contentful experience.
Please have a look at the Contentful CLI migration command documentation to learn more about how to use this as command line tool.
const { runMigration } = require('contentful-migration')
const options = {
filePath: '<migration-file-path>',
spaceId: '<space-id>',
accessToken: '<access-token>'
}
runMigration(options)
.then(() => console.log('Migration Done!'))
.catch((e) => console.error(e))
In your migration description file, export a function that accepts the migration object as its argument. For example:
module.exports = function (migration, context) {
const dog = migration.createContentType('dog')
const name = dog.createField('name')
name.type('Symbol').required(true)
}
You can also pass the function directly. For example:
const { runMigration } = require('contentful-migration')
function migrationFunction(migration, context) {
const dog = migration.createContentType('dog')
const name = dog.createField('name')
name.type('Symbol').required(true)
}
const options = {
migrationFunction,
spaceId: '<space-id>',
accessToken: '<access-token>'
}
runMigration(options)
.then(() => console.log('Migration Done!'))
.catch((e) => console.error(e))
| Name | Default | Type | Description | Required |
|---|---|---|---|---|
| filePath | string | The path to the migration file | if migrationFunction is not supplied |
|
| migrationFunction | function | Specify the migration function directly. See the expected signature. | if filePath is not supplied |
|
| spaceId | string | ID of the space to run the migration script on | true | |
| environmentId | 'master' |
string | ID of the environment within the space to run the | false |
| accessToken | string | The access token to use | true | |
| yes | false | boolean | Skips any confirmation before applying the migration,script | false |
| retryLimit | 5 | number | Number of retries before failure (every subsequent retry will increase the timeout to the previous retry by about 1.5 seconds) | false |
| requestBatchSize | 100 | number | Limit for every single request | false |
| headers | object | Additional headers to attach to the requests | false |
All methods described below can be used in two flavors:
The chained approach:
javascript
const author = migration
.createContentType('author')
.name('Author')
.description('Author of blog posts or pages')
The object approach:
javascript
const author = migration.createContentType('author', {
name: 'Author',
description: 'Author of blog posts or pages'
})
While both approaches work, it is recommended to use the chained approach since validation errors will display context information whenever an error is detected, along with a line number. The object notation will lead the validation error to only show the line where the object is described, whereas the chained notation will show precisely where the error is located.
migrationThe main interface for creating and editing content types and tags.
createContentType(id[, opts]) : ContentTypeCreates a content type with provided id and returns a reference to the newly created content type.
id : string – The ID of the content type.
opts : Object – Content type definition, with the following options:
name : string – Name of the content type.description : string – Description of the content type.displayField : string – ID of the field to use as the display field for the content type. This is referred to as the "Entry title" in $ claude mcp add contentful-migration \
-- python -m otcore.mcp_server <graph>