Using HTML API to get preview pages

We’re wanting to use the HTML API to get the rendered HTML of a given page from builder.io.

However, it appears that we can only get the published content, not preview/unsaved content in the HTTP API response

We’re passing along ?includedPublished=true&cacheSeconds=1.

Example curl request:

curl -X GET ‘https://cdn.builder.io/api/v3/html/page?apiKey=KEY&cacheSeconds=1&includeUnpublished=true&url=%2Fbuilder_preview%2Ftest-123

This returns the published content, not the preview content.

Is it possible to get the rendered HTML Preview content somehow from Builder’s API?

Hi @joevandyk,

To fetch preview content using the HTML API, you need to use the correct parameters to ensure it includes unpublished or draft content. The issue you are facing is likely because the API request is not properly configured to fetch the preview content with the current parameters.

  1. Ensure that includeUnpublished is used correctly: Double-check that the parameter includeUnpublished=true is indeed being used in the API request. This parameter is intended to fetch both published and unpublished content.

  2. API Key Permissions: Verify that the API key you are using has the appropriate permissions to view unpublished and draft content. Depending on your organization’s setup and model privacy settings, additional configurations might be necessary to allow access to certain content states.

  3. Preview Environment Configuration: If you have multiple environments within Builder.io (like staging or production), ensure that your request is targeting the correct environment where your draft or preview content exists.

  4. Cache Management: Since you are using cacheSeconds=1, ensure that this is not causing issues by serving cached versions beyond the expected time. You can also try setting cacheSeconds=0 for immediate no-cache behavior while debugging.

  5. Exact URL and Path: Double-check the URL segment you are using (url=%2Fbuilder_preview%2Ftest-123) to ensure it corresponds to the actual path set within Builder.io. You might need to conform to the exact URL path as configured in your Builder.io model settings.

If the above steps do not resolve the issue, feel free to let us know.

It would also be beneficial to check the HTML API documentation for any updates or changes in parameters or usage guidelines.