Hi there,
I am trying to fetch my linked documents with the JS api. I saw the documentation post here Fetch Data with Vanilla JavaScript - Prismic but unfortunately it doesn't quite help.
What I am trying to achieve is the following:
I have a content type on which an editor can choose "recommendations" and link to two articles of the same content type that will be rendered in our frontend as teasers.
In our code, I would like to get the information (e.g. image, description etc.) of those linked items. It worked well with GraphQL but we're switching to the JS Api and I just can't get it to work.
So my current implementation looks like something like this:
export async function jsApiCall(
uid: string,
lang: string,
) {
const client = PrismicClient
const response = await client.query(
Prismic.Predicates.at('my.CONTENT_TYPE.uid', uid),
{ lang, fetchLinks: 'CONTENT_TYPE.recommendations.single_recommendation' },
)
return response?.results?.[0]
}
I used the recomendations.single_recommendation
query because our custom type looks like this:
How would a proper query look like using the JS API when I want to query linked items of the SAME content type?
Thanks!