Getting the root content entry for a given entry in the tree

We’ve organized our content such that there are a bunch of top level Page entries. Each page has the content for that page on the website. The structure varies depending on the page that it is in and there are a bunch of linked entries below the parent Page entry.

When I publish an entry somewhere in the tree, it fires a webhook and in that webook request the JSON for the single entry is included. I need to know the Pages that include the changed entry so that I can clear a cache for that page. For instance, if I change and publish a “Product Card” that is used on two pages, I would like to know what two pages contain the changed product card.

Is it possible to query all the top-level entries for a given child entry? I don’t see a way.

I think my solution may be to query all entries in our app of type “page” and then recursively walk them to see if the changed entry is in that tree.

3 Likes

I’m interested in hearing an answer to this as well. We’re going to run into the same issue.

If references were “bi-directional”, it seems that you’d simply be able to walk backwards up the tree to find all Pages.

We call this Incoming Links and it is on our product roadmap. We are working on it and plan to release this feature soon.

In the meantime, you can search for entries based on the value of a reference. For example, you could search for all pages which have a reference to a specific Product Card. See https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/search-on-references for details.

There are some limitations though; the biggest one is that it only works on single reference fields, not multiple reference fields. Also it is only possible to search one level deep (e.g., if your model was like this: Page -> Product Group -> Product Card, you wouldn’t be able to directly find the pages which have a specific product card. It would take 2 api calls to get that).

We hear you though and are working hard to implement this as fast as we can!

2 Likes

Update!!! We’ve released a new set of API search parameters which filter entries that have a field linking to a given entry (links_to_entry) or asset (links_to_asset). Available under the /entries endpoint, these search parameters ease the process of navigating the content graph from children up to their parents in a single API call.

See these links for more info:

3 Likes

Is there any way I can find the root content in the graph from the children which is deep more than 2 levels?

Trying with the updated API to get links_to_asses it’s returning just an array of the immediate parent of the current child. Is there any way I can access the parent that is more than 1 level above in the content graph in just one API call?

1 Like

I have the same question as @rajendrasinh.parmar. I thought when I used links_to_entry previously I could specify my “page” content type in the sys.contentType.sys.id query but that doesn’t seem to be working anymore. Would be very handy to get the top level parent entry without having to make multiple API calls.

@rajendrasinh.parmar @dfoxpowell I’m looking for the same solution without having to make multiple API calls to find the root element – following this thread!

1 Like

Can we get support for this? There is clearly a need.

Hey, does anyone have a solution for this ?

We’re trying to make Contentful works with Next.js On demand Revalidation, we’re getting stuck on finding the root content of the published entry that triggered the webhook.

1 Like

Same, for on-demand revalidation finding the root “page” would be key to understand which page(s) we need to rebuild when a piece of underlying content changes. Otherwise we’d have to traverse up the “link tree” which is just a pain :frowning:

I think this is a needed functionality.

Any update on this, I’m also trying to implement nextjs revalidation and this feature would be a life saver

Hi Team,

We are also needing this feature can you please provide with any update on this @contentful12 .

1 Like

Hi everyone,

we are currently in the same situation as most of you. We use Webhooks to determine scheduled content and want to invalidate our Redis entries. The whole “links_to_entry”-thingy is working quite good, but you have to use the PREVIEW API, which was a bit confusing for me.

Not sure if this is intentional