2

I'm new to using Contentful and the issue I have is the following:

I created a content model A with 10 different fields and I created 30 entries for that content model.

However, I realised that this content model is not suitable for my use case and so I created another B with 8 fields all of which are the same as A.

So I'm wondering if there's a way to somehow transform my existing 30 A-type entries into B-type entries instead of manually creating them?

1 Answers1

1

Contentful DevRel here.

To transform data and automate certain content operations you have to use the Content Management API (CMA). The write-API allows you to script changes and perform changes programmatically.

On top of this API, we provide Migration tooling. To migrate 30 entries over to another Content Type you can leverage the CLI tooling and write a migration script using the transformEntriesToType function.

Example creating copycats from dogs from the docs:

migration.transformEntriesToType({
    sourceContentType: 'dog',
    targetContentType: 'copycat',
    from: ['woofs'],
    shouldPublish: false,
    updateReferences: false,
    removeOldEntries: false,
    identityKey: function (fields) {
      const value = fields.woofs['en-US'].toString();
      return MurmurHash3(value).result().toString();
    },
    transformEntryForLocale: function (fromFields, currentLocale) {
      return {
        woofs: `copy - ${fromFields.woofs[currentLocale]}`
      };
    }
  });
stefan judis
  • 3,416
  • 14
  • 22