Contentful API how to get all entries from a contentType?

Hi,

I’m trying to pull entries from a contentType but I can’t seem to get it to work. The content is set up this way

- ContentType
       - SectionEntry (entry inside the content type)
            - ItemEntry1 (entry inside the section)
           - ....
      - SectionEntry
            - ItemEntry
            ....

I’m trying to get all the item entries from the section entries. My current solution to grab them is by hard coding the ID values of SectionEntry storing them in an array and passing them into the getEntries() method. But this method crashes the site if any of the SectionEntry is deleted from contentful.

So is there a way to get the IDs of SectionEntry just by requesting the contentType?

I’ve tried passing in the ID of the contentType into getEntry() and get getContentType() but none of them return the sections.

Doing this:

client
      .getContentTypes()
      .then(response => {
        console.log(response);
      })
      .catch(console.error);

gives me this:

As you can see I querying the contentType doesn’t give me the sections inside it. I’ve also tried getEntry() and passed in the ID of the contentType via the URL and that too doesn’t work.

I’d appreciate any kind of help, thanks!

Hey @harowitzblack,

You may need to include an object that has the includes field with the value of how many nested entries you want to include.

For example,

    const response = yield client.getEntries({
      content_type: contentType,
      include: 5, // The number of nested CMS entries to include
    });

I’m not sure if getContentTypes supports options though so you may need to use a different get function.

I’m using JavaScript/TypeScript :smiley:

Hopefully this helps!