Contentful logo

Contentful Community

Links to entries - how?

I have a content model “Content page” with some typical fields MainTitle, Slug, Ingress and PageContent.

The frontend fetches the page based on the current url, extracting a slug then querying for that slug.
e.g. queryParams = {contentType: “contentPage”, “fields.slug” = theSlugExtractedFromCurrentUrl};

This works great, we retrieve the correct page every time. Fast and wonderful. However, we want to include a sidebar with links to other pages. So we added a new field to this model, “Multiple references”, allow only references to other Content pages.

Great, each page can now assign its own sidebar, just like we wanted. Problem:
Doing a query now the result includes all the selected references with all the fields fully populated when we only want the mainTitle and slug. (link label and link href) That’s a lot of unecessary data for a few links.

I check the contentful delivery api document, which explains how to only select specific fields using the “Select operator”. However, this tells me it only allows 2 levels deep selections, e.g. “fields.mainTitle”. Selecting something like [“fields.sidebarLinks.mainTitle”, “fields.sidebarLinks.slug”, andTitleIngressContentFields] is not possible, because that’s 3 levels deep.

Then I tested the “Link” => “link to entry” in the rich text editor. Same story here, the full entries are included. Too much data (well, could be a lot if the main content is large and there are a lot of links)

Now I’m thinking I need to send a second request to the contentful api, where I ask for all titles/slugs for pseudoselection: IN = [sidebarLinksEntries.sys.ids]
The resulting list of slugs/titles will surely populate the sidebar, but is this extra request necessary?
Is there any way to avoid extra data in the single request, and at the same time avoid extra requests?
Any other suggestions or thoughts?

Using Restful API, I think the solution is either of the two that you have mentioned; to get exact data the application needs, GraphQL is a good choice.