How to fetch a record from prismic repository by specifying required fields

How to fetch a record from prismic repository by specifying required fields through API
for example :
[at(document.type,"product")]
fetch product.product_name

we have tried to fetch the details with below query and it is not working

Hello @peter

Welcome to the Prismic community, and thanks for reaching out to us.

fetch is a search parameter. You need to add a search parameter in the query URL. When Querying the API Browser, you need to add search parameters before the hashtag (#) in the URL to get filtered results.

For e.g., In your case, add a search parameter in the URL after querying the API browser like:
&fetch=bundle.bundle_name

Learn more about the Search parameter here.

Let me know if you have further questions related to it.

Thanks,
Priyanka

Hi Priyanka,

Thank you for the support.

In Postman we are able to get it. But in browser as below screen shot we are unable to get it.

image001.png

Regards,

Peter

It should work in the API browser as well. After querying the API browser, you need to put search parameters in the query URL.

For instance:

  1. Hit the API browser with your-repo-name/prismic/api/v2 this URL.
  2. If the API browser URL is: https://your-repo-name.prismic.io/api/v2/documents/search?ref=WmdIBCcAAHhUDe_K#format=html
  3. Then, to fetch a page with only one specific field, add the fetch parameter after the "ref" and before the hashtag (#) in the URL to get filtered results. I am adding &fetch=page.image in the URL to fetch only an image field from the page.
    https://your-repo-name.prismic.io/api/v2/documents/search?ref=WmdIBCcAAHhUDe_K&fetch=page.image#format=html

Now you change your-repo-name with your repository name and add fetch search parameter.

I hope it's clear now and if you have any further questions, please let me know.

Thanks,
Priyanka