Contentful logo

Contentful Community

Get a response where data that is under "[includes]" array is under "[items]" instead

I was browsing the developer docs when I came across this:

Searching on references has the following restrictions:

*** You can only search on references on fields which link to a single entry. Fields which hold references to many entries or fields with references to assets are not supported.**

Is there anyway to have JSON be returned where the Items array also contains the data members from a list of references?

Hi @anthony.schanen,
I’m not sure I understood the question correctly. From the title I deduce that you would like to change the output format, having the data directly inline with the items, instead of having to lookup them in the include section. If so, that is not possible with standard CDA, but it might be possible with GraphQL, using a nested query and maybe even fragments (pieces of GraphQL query) that allow you to represent a particular item.

Hey Alma, yes that is what I meant, and thank you for the response!

Unfortunately I’m in a pickle here with GraphQL query’s. That was my original technique, but since I am using a website building tool to create a site, and it does not naively support graphQL with its API connection functionality, I would have to write a plugin to add it. Although it achieves the goal it has disadvantages within the site builder.

I’m curious though, what was the logic for the choice of separating these instead of having them inline with the items. My guess is performance server-side, but I wouldn’t know. I’m new to web development, and currently in college for computer science, so I’m trying to learn as much as possible.

Thanks so much again, I appreciate your help!

Hi @anthony.schanen,

The reason behind such a choice is a standard practice in designing API. The common scenario is where you have the main entry response, that can link more than once to other resources. Therefore would be inefficient to embed the additional resource inline; it is better to have the link to other resources in the main response, and the linked resource ‘body’ in a separate section.

I hope this clarifies the issue.