This document serves as a comprehensive guide to Contentstack's Preview API. The Preview Service API enables the retrieval of content for previewing from your Contentstack account. Both Live Preview and Timeline utilize this service to display pertinent data.
The Preview Service API supports all routes of the Content Delivery API. By switching the host from CDN to the preview hosts specified below and including the headers provided, you can access content for preview.
Since the Preview Service APIs are private, you must include specific HTTP headers to make authorized requests:
The API Key is a unique key assigned to each stack. The Preview Token is a read-only credential that can be created alongside the Delivery Token.
Additional Resource: Learn more about creating preview tokens.
HTTP headers let the client and the server pass additional information with an HTTP request or response. An HTTP header consists of its case-insensitive name followed by a colon (:), then by its value.
Example for REST:
curl 'https://rest-preview.contentstack.com/v3/content_types/page/entries' \
-H 'api_key: {api_key_of_your_stack}' \
-H 'branch: {branchName || branchAlias}' \
-H 'content-type: application/json; charset=UTF-8' \
-H 'live_preview: {live_preview_hash}' \
-H 'preview_timestamp: {desired_iso_timestamp_for_preview}' \
-H 'preview_token: {your_preview_token}'Example for GraphQL:
curl -g \
-X POST \
-H "Content-Type: application/json" \
-H "preview_token: {your_preview_token}" \
-H "branch: {branchName || branchAlias}" \
-H "live_preview: {live_preview_hash}" \
-H "preview_timestamp: {desired_iso_timestamp_for_preview}" \
-d '{"query":"query($locale: String){all_blog(locale: $locale){items{title}}}","variables":{"locale":"en-us"}}' \
https://graphql-preview.contentstack.com/stacks/{api_key}