Contentful logo

Contentful Community

getEntry on page to return all nested data

#1

I have content type (home page) with a field referencing another content type (section). Within that content type, I have a field with a reference to 1 of many (section items). When I run getEntry and query the home page, I am not getting all the data returned. I am not getting the fields for the section items. Any ideas?

0 Likes

#2

Hi @jason.justice,

Could you confirm if you’re using an appropriate level of include and that you have link resolution enabled in your client setup? (resolveLinks: true)

https://www.contentful.com/developers/docs/concepts/links/

0 Likes

#3

I’m not sure how to answer the first question.

I’m doing this to get the entry content

client.getEntry(‘THISISTHEIDOFMYPAGE’)

For the 2nd, where do I enable this?

0 Likes

#4

OK I read the linked support doc. I get the concept but would this now require me to make 2 call to the API for content. One for the page and another to get the linked items? Ideally I’d like to just make 1 call for the page content and get everything. Is this possible?

0 Likes

#5

I first missed you were querying a single item (getEntry). It wouldn’t be required at all to make two requests. :slight_smile:

Instead, you can use a query on the lines of the query:

getEntries({include: 3, ' sys.id' ': 'EntryID'}

The include parameter unfortunately doesn’t work in the single entry endpoint, so you’d use the /entries endpoint narrowing it down to that specific item.

Let me know if that makes sense or if you have any other questions :smile:

0 Likes

#6

Thanks! So the entryID can still be the ID for the entire page. Correct?

0 Likes

#7

If your page is based entirely on that given entry (including referenced items), then that’s correct.

0 Likes

#8

I got it working. Thank you. Is the value of the ‘include’ parameter relative to the number of levels down I’m going into the content? I’m a little confused there.

0 Likes

#9

That is correct. The include parameter indicates how many levels of resolving you’d like in your query.

0 Likes