Contentful logo

Contentful Community

Retrieve linked entries

Hello,

I am creating a UI extension for a field that holds an array of links to other entries.

I managed to add links to the array in the form of:

[ sys: { type: 'Link', linkType: 'Entry', id: 'id of the entry' } ]

I can see the ids of these links in sdk.field.items but how can I get their names?

I tried using sdk.spage.getEntries with include but still can’t get them.

What problem/error are you having exactly?

The management api doesn’t do link resolution (which means the UI Extension SDK doesn’t either), so it might be useful to instantiate a delivery or preview api client inside your UI Extension simply to get the tree of content more easily.

For example, I built a nested category browser UI extension which displays a tree of categories to reference from another entry and I used a CDA client to get the tree of categories within my UI extension.

I hope this helps!

You also could iterate through all the entries and for each reference do a space.getEntry(id) to get all the names. Or you could do it in one api call like

space.getEntries({
  content_type: 'content_type_id', 
  // a comma separated string of all the entry ids
  'sys.id[in]': '16kHM2yIJOdZbV4TTQ2E5i,4WOwG2lL15gEG62TckFZXW' 
}).then(response => {
  // get the entry names
})

Hope this helps!