2

Im using the Content-Managemen-API provided by contentful.

Im using this to create a single entry in a space and this works fine:

const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})


client.getSpace('<space_id>')
.then((space) => space.createEntry('<content_type_id>', {
  fields: {
    title: { 'de-DE': 'Zusammenfassung', 'en-US': 'Summary' },
    slug: { 'en-US': 'example-app-summary' },
    modules: { 'en-US': [Object] }
  }
}))
.then((entry) => console.log(entry))
.catch(console.error)

My Problem:

I want to create a nested entry. Which means an entry contains another entry and so on.

I have tried the sending contentful this data strcuture:

fields: {
    title: { 'de-DE': 'Zusammenfassung', 'en-US': 'Summary' },
    slug: { 'en-US': 'example-app-summary' },
    modules: { 'en-US': [Object] }
  }

The modules property contains another entries meta-data shown below:

{ type: 'Link', linkType: 'Entry', id: '4Ng6zmj9e8Sw0eaYKQM8Es' }

When I do a POST request with the above data, it does create a Entry but the nested entries don't work and I see this.

enter image description here

Question:

Anyone know how I can create an entry with nested items? Im not sure what data structure to send to the API.

Skywalker
  • 4,984
  • 16
  • 57
  • 122

1 Answers1

0

I believe you're missing the sys key. E.g.,

fields: {
  title: { 'de-DE': 'Zusammenfassung', 'en-US': 'Summary' },
  slug: { 'en-US': 'example-app-summary' },
  modules: { 'en-US': [
    {
      sys: {
        type: 'Link',
        linkType: 'Entry',
        id: '<module-entry-id>',
      },
    }
  ]},
}

References:

  1. https://www.contentfulcommunity.com/t/creating-entry-with-associated-resource-specified/670/5
  2. https://github.com/contentful/contentful-management.js/issues/57#issuecomment-451435472
Conor
  • 1