Resolving a very deep relationship structure

Hi there,

I’m attempting to pull a content piece that has a very involved structure. I believe I’m getting confused by the path structure in the JSON vs. how the blocks are built.

You can find the data structure here:https://api.storyblok.com/v1/cdn/stories/home?version=draft&token=68wmQY1wg0GVarhLzA33Jgtt&cv=1599083039&resolve_relations=programs-layout.programs

I’m attempting to resolve the story in the media field. If I were using JSONPath it would be located here: story.content.body[2].programs[12].content.tabs[3].media

I’ve tried a number of variations similar to this programs-layout.programs.program.tabs.media

Is there not an easier way to identify components you want resolved without specifying the full path? In this whole data structure I basically need all the component stories.

Thanks for your help,

David

Hello David,

embedded relations which are inside of resolved relations can’t be resolved using the resolve_relations parameter. Instead oft that you can use the by_uuids parameter to fetch them separately:
https://www.storyblok.com/docs/api/content-delivery#core-resources/stories/retrieve-multiple-stories

Here is an example which shows how you can use it to get the stories of the media fields using their UUIDs:
https://api.storyblok.com/v1/cdn/stories?version=draft&token=68wmQY1wg0GVarhLzA33Jgtt&cv=1599083039&by_uuids=688d6efd-7762-448b-a9dc-9f15232e5257,94546af1-7233-43ea-acd3-f4e6439cae8b,a482c19a-609b-4938-bec5-2ad434306cae,1b8981b0-f95c-4597-98c4-9a8fe64ae0d4

Hi Hannes, thank you for answering so quickly. This unblocks me! It would be really nice if there was a way to recursively fetch these values. It would simplify the logic in my Next.js data resolvers.

You’re most welcome David!

There were already other people who asked about this possibility. Unfortunately there are technical hurdles which prevent this from becoming a possibility:

That’s understandable. At scale (as an engineer) I can see that it would be cumbersome. Perhaps a separate service designed specifically for resolving this issue? Story Resolver or something similar would make sense. Basically supply the base query and the service iterates through all the components and resolves relations.

That’s basically what I’ve written in my client but it’s slow and cumbersome given the amount of data we’re working with. Something that fetches the data and mitigates the 100-200ms round-trips to the UUID endpoint would save a bit of effort.

Given that SB has received many similar requests and given that this may mitigate effective and/or efficient utilisation of your service, I’d strongly recommend considering it. =)

Thanks again for your support.