Browse the API with Postman

You can make API requests to your Prismic Repo with the Postman REST client. This article demonstrates how you can do it with a GET request.


To browse your REST API with Postman, perform the following steps:

Go to your Postman account and create a new GET request. Click on New > Request.

GET request window

Add the following script to the Pre-Request Script tab in your Postman GET request. This script fetches the master ref before running any API call and saves it in an environment variable. If the URL of your repository is https://my-awesome-blog.prismic.io, then replace your-repo-name with my-awesome-blog.

Copy
pm.environment.unset("ref");

// update this variable with your repo name
var repo = "your-repo-name"

pm.environment.set("repo",repo)
var repoEndpoint = "https://" + repo + ".prismic.io/api/v2"

pm.sendRequest(repoEndpoint, function (err, res) {
  if (err) {
    console.log(err);
  } else {
    var response = res.json();
    var ref = response.refs[0].ref;
    pm.environment.set("ref", ref);
  }
});

Master Ref

The API ref is required to specify the content version you want to query. For published content, use the master ref. Learn more about the Rest API browser here.

Now, go to the Params tab and set the master ref as a key-value pair.

Set up the master ref as a query params in Postman

Enter the below URL template in the URL field. Then, click on Send at the top right to make the API request.

Copy
https://{{repo}}.prismic.io/api/v2/documents/search?ref={{ref}}
Set URL in the GET request

The API call should return with a response under the Body tab.

If you have set your repository private, you need to add an access token. To add an access token, go to the Authorization tab of Postman. Select Bearer Token from the Type dropdown, and paste the access token in the Token box. Learn more about how to generate an access token here.

Add access token in the Authorisation tab

You can find all the REST API references here.


Was this article helpful?
Not really
Yes, Thanks

Can't find what you're looking for? Get in touch with us on our Community Forum.