How to fetch draft/autosaved content before publishing in Next.js?

I’m trying to view draft content from Builder.io in my Next.js 15 app before publishing. I can see published content fine, but need to preview autosaved changes.

Setup:

  • Next.js 15 (App Router)

What I’ve tried:

// Attempt 1: includeUnpublished

const content = await builder.get(“page”, {

userAttributes: { urlPath: “/my-page” },

options: { includeUnpublished: true, cachebust: true }

}).toPromise();

// Still shows published version

// Attempt 2: builder.overrides

const draftUrl = `https://cdn.builder.io/api/v3/content/page?apiKey=${apiKey}&userAttributes.urlPath=${urlPath}&builder.overrides.page=${contentId}&builder.preview=page&builder.noCache=true&builder.cachebust=true\`;

// Still shows published version

Question:

How do I fetch the latest autosaved/draft content (unpublished changes) in Next.js? Is there a specific API endpoint or parameter I’m missing?

The page has hasAutosaves: true but I can only see published content regardless of parameters used.

Thanks! :folded_hands:

Hello @rahulhc ,

Thank you for reaching out and for sharing the details of your setup and tests.

In your current implementation, it looks like the includeUnpublished flag is being passed inside the options object. This parameter should instead be passed at the top level of the API call, not within options.

Here’s an updated example that should correctly fetch autosaved or unpublished content:

const content = await builder.get('page', {
  userAttributes: {
    urlPath: '/my-page',
  },
  includeUnpublished: true,
  cachebust: true,
}).toPromise();

This ensures the Builder API includes unpublished or draft versions when available.

You can find more details and working examples in our documentation here:

Please give this a try and let me know if you’re still unable to retrieve draft content afterward.

Thanks,