Server-side query of previews

Before I get too in-depth in spitting out templates, I want to make sure my build tools will be able to get hold of data in preview and build on a staging site before publishing content.

It appears that I have to have a browser client pass cookies into my build process that needs to serve my website and re-route a preview url?

What is the point of having an access token set up that should have access to previews?

Expected Behavior

It seems like I should be able to pass a request to the api to get all the refs which are various preview refs. And then I should be able to use one of the refs to query for the content of that preview.

If I were to query that "ref", I would assume that I'd get content from Master with the exception of new content from the "ref" where available.

Current Behavior

When I initiate the API, I get a list of refs that ONLY includes the master ref.

Documentation Referenced

What I've done

For the sake of exploration, I was able to set up an express server to do what the documentation seemed to be saying.... kinda.
I ended up skipping the Prismic js client, and using axios. I also wrote my own parser to get the "ref" out of the preview url passed from the prismic UI.

This seems to miss the point of a staging environment where a build can just reference the Prismic API and create a full (not just one page), website build.

Also, if I were going to create an iOS app using this, how would I test new content? I wouldn't have a browser to pass a cookie through.

1 Like

Hi Ethan,

So the cookie that’s returned in the browser is itself a ref, but is only valid for as long as the content is valid i.e. if it hasn’t been published, archived or moved to a release. This ref will return the draft version of the document and the live version of every other document. This is only intended for short quickly changing previews.

For more advanced staging like yours and apps the best thing to do is use our releases feature.

With a release you will be able to get a ref that you can access through your api browser:
https://your-repo-name.prismic.io/api

You’ll need to click the padlock icon to unlock access to the release refs from the browser
https://prismic.io/docs/rest-api/basics/the-api-browser#2_0-select-a-ref

You can then pass this ref to your project to preview that content. The release will contain the draft content for any documents that you add to this release and the live content for anything not in the release.

Hopefully this helps.

This issue has been closed due to inactivity.