How can we get draft pages from builder.io in next js app

How we can get unpublished pages from builder.io ?
is there any Api to get all the pages published and unpublished (draft) pages?

Hi @olivela,

Thanks for reaching out.

Yes, you can get the latest draft from the API, it requires knowing the content ID, so you’d make an extra API Call to get the latest draft, something like:

import { builder } from "@builder.io/react" // or `@builder.io/sdk`

builder.init(process.env.BUILDER_API_KEY)
export async function resolveBuilderContent(modelName: string, userAttributes: Record<string, string | number>, loadLatestDraft = false) {
  let page = await builder.get(modelName, { userAttributes }).toPromise();
  if (page && loadLatestDraft) {
      page = await fetch(`https://builder.io/api/v2/content/${modelName}/${page.id}?apiKey=${apiKey}&preview=true&noCache=true&cachebust=true`).then(res => res.json())
  }

  return page;
}

To know more you can visit our forum post API parameter to include not yet live content.

Let us know if you have any further questions. Thank you!

always getting undefined response for draft pages .
is there any other way to get Draft pages ?

Hi @olivela,

You can also fetch the draft pages with the builder.get() method passing the option includeUnpublished=true. You can find more help at Builder Content API.

Let us know if you have any further questions. Thank you!