Search code examples
content-management-systemcontentful

How to duplicate Contentful content model


How to duplicate Contentful content model via https://github.com/contentful/contentful-migration? It can definitely be done via Web UI as shown below

Duplicate button in UI

Seems like there is no such an option in management API https://www.contentful.com/developers/docs/references/content-management-api/


Solution

  • Indeed it appears there is no single request that will duplicate a content model.

    You would need instead to make two requests, first fetching the content model you want to duplicate, then creating the new model derived from it:

    1. Fetch the source model:

      GET /spaces/{space_id}/environments/{env_id}/content_types/{content_type_id}

    2. Prepare the request body to create the duplicate model: from the response to step 1, remove sys and update name to differentiate from the source model

    3. Create the new model, using the request body from step 2:

      PUT /spaces/{space_id}/environments/{env_id}/content_types/{new_content_type_id}