Mojimoto Docs
Start free
Docs Concepts Preview and drafts

Preview and drafts

Show unpublished drafts on your own site with a preview token and ref=preview, and open an entry's preview straight from the editor.

An entry is a draft until someone publishes it, and every edit after that is a new draft on top of the published version. Entries and publishing covers that cycle. The Delivery API serves published content only, so a live site never shows unfinished work.

To look at drafts there are two things to use. The API serves drafts to a token that is allowed to ask for them, and the entry editor has preview buttons of its own.

Ask the API for drafts

Drafts come from the same endpoints as published content. Two things together switch them on:

  1. A token with the preview ability.
  2. ref=preview on the request.

An admin or owner creates the token on the project's API keys page: under Custom tokens, give it a name and tick preview. The public read token every project comes with cannot preview.

terminal
curl "https://mojimoto.com/api/v1/acme/documents?type=post&uid=hello-world&ref=preview" \
  -H "Authorization: Bearer mjmt_your_preview_token"
json
{
  "results": [
    {
      "id": 42,
      "uid": "hello-world",
      "type": "post",
      "lang": "en-gb",
      "status": "draft",
      "published_at": null,
      "updated_at": "2026-11-26T09:14:02+00:00",
      "data": { "title": "Hello, world (edited)" }
    }
  ],
  "page": 1,
  "per_page": 20,
  "total_results": 1,
  "total_pages": 1,
  "lang": "en-gb",
  "ref": "preview"
}

With ref=preview:

  • Each entry comes back in its newest version: the working draft if there is one, otherwise the published version. status says which. Entries that have never been published are included.
  • Linked entries are resolved the same way, so a draft page shows its draft sections.
  • Filters, sorting, lang and locale fallback work as they do for published content, against the draft values.
  • The response is sent with Cache-Control: no-store, private. Do not cache it yourself either.

The same parameter works on a single entry, GET /documents/{id}?ref=preview. The Preview API reference has the full list.

When the token cannot preview

A request with ref=preview from a token without the preview ability is not an error. It gets published content, "ref": "published", and this header:

text
X-Mojimoto-Preview: denied - token lacks the "preview" ability, serving published content

A staging site with the wrong token keeps rendering. If drafts are not showing up, look for that header first.

Preview from the editor

The entry editor has a Preview card with up to two buttons.

Styled preview opens the working draft in a new tab, laid out by Mojimoto from the content type's fields: the title field as the heading, the first media field set to cover as the hero image, the first rich text field as the body, and the remaining fields beneath. It needs no front end, and anyone who can open the project can use it. It is a sketch of the content, not your site.

Open on site opens the entry on your own site. It appears once two settings are filled in.

Setting Where Example
Preview base URL The project's Settings, under Preview. Admins and owners. https://www.example.com
Preview path Content model, the content type, Settings. Developers and above. /preview/{type}/{uid}

The two are joined to make the link. The path can use these placeholders:

Placeholder Replaced with
{type} The content type's API id.
{uid} The entry's uid, or its id when it has none.
{id} The entry's id.
{locale} The locale being edited.

The button is a plain link. Mojimoto adds no token or signature to it, so whether that address shows drafts is up to your site.

Entries linked through a reference field appear as cards in the editor. When a linked entry has a preview link, an editor can capture a screenshot of it for the card. The screenshot is taken by loading the link with no login, 1280 pixels wide and 800 high, so the address has to be reachable from the internet.

Wire up a preview route on your site

The least work is a staging copy of the site that always sends the preview token and ref=preview, while production sends a read token and no ref. Same code, two sets of environment variables.

To preview on the live site, add a route that turns drafts on for one browser:

  1. Keep the preview token on the server. It can read unpublished content, so it must not reach the browser.
  2. Add a route that checks a secret from the query string, sets a cookie or your framework's draft mode, and redirects to the page.
  3. While that is set, fetch with the preview token and ref=preview, and skip your own caching.
  4. Point Open on site at the route.

In Next.js the @mojimoto/next package provides the route:

app/api/preview/route.ts
import { createPreviewHandler } from '@mojimoto/next/preview'

export const GET = createPreviewHandler({
  secret: process.env.MOJIMOTO_PREVIEW_SECRET!,
})

It expects secret and redirect in the query string, so the content type's preview path becomes:

text
/api/preview?secret=your-secret&redirect=/blog/{uid}

An editor who chooses Open on site is sent through the route and lands on /blog/hello-world with drafts on. The pages themselves fetch with createDraftAwareClient, which asks for drafts only while draft mode is on. Next.js has the full setup, and Nuxt and Laravel have their own versions of the same idea.

Something wrong or missing on this page? Tell us and we will fix it.

© 2026 Your Ikigai Ltd · Registered in England & Wales, no. 15274889 文 · モジモト