Skip to content

Build a site with Site Kit and cms-sdk

Page

Guide

Updated 13/11/2026

The CMS does not draw a front end. A site only reads published content and shows it; you, an agency or an AI tool can build it, and it can be rebuilt at any time because the content stays in the CMS. Site Kit gathers the parts that are hard to get right: a machine-readable content model, sample code for Next.js, Astro and plain JavaScript, and the check command.

Before you start

  • A CMS site with at least one public content type and some published entries.
  • A store key (cmspk_…) for that site. An administrator issues it in the Console; see Set up a content site.
  • To fetch the Site Kit bundle the key needs the kit feature; for draft preview it also needs preview.

Steps

  1. Export the Site Kit bundle so the build tool has the full context: type schemas, blocks, brand tokens, the “never do” rules and sample code.

    Terminal window
    npx @datazen/cms-site-kit export
  2. Read content with the Store API. Send the key in the x-publishable-api-key header:

    Terminal window
    curl -H "x-publishable-api-key: $CMS_STORE_KEY" "$CMS_URL/store/cms/site"
    curl -H "x-publishable-api-key: $CMS_STORE_KEY" "$CMS_URL/store/cms/types/article/entries?limit=10"
    curl -H "x-publishable-api-key: $CMS_STORE_KEY" "$CMS_URL/store/cms/resolve?path=/about"
    • GET /store/cms/site returns the site’s languages, time zone and base_url.
    • GET /store/cms/resolve?path= turns a site path into an entry, a redirect or a 404. Build every page from it; do not guess paths.
    • The site and type scope come from the key. Do not send site, site_id or env in the query: the CMS answers 400.
    • Send If-None-Match with the ETag you received to get a 304 when nothing changed.
  3. Build the sitemap, robots and redirects from /store/cms/seo/* instead of writing your own.

  4. Add draft preview, webhook refresh and, if you take enquiries, forms.

  5. Run check against the deployed site:

    Terminal window
    npx @datazen/cms-site-kit check https://your-site.example

Read content with cms-sdk

The @datazen/cms-sdk package is a read-only Store API client with types generated from OpenAPI, ETag handling, retries and a stale fallback when the CMS is slow (the stale flag):

import { createStoreClient } from "@datazen/cms-sdk"
const cms = createStoreClient({ baseUrl: process.env.CMS_URL!, key: process.env.CMS_STORE_KEY! })
const { data, stale } = await cms.call("storeListEntries", { path: { type: "article" }, query: { limit: 10 } })

The SDK has no write operations: submitting forms and opening a preview session are still direct calls, as in those guides.

Reading the check result

  • Green means the DataZen side is fine. Red names the exact rule that failed, for example rule.never.utm.
  • A check that needs the CMS and could not run is reported as skip with a reason, never as a false pass.
  • SEO checks (page description, share tags, robots, redirect map) run with --seo. A site without a CMS uses --no-cms.
  • Keep the store key on the site’s server or in an environment variable; never in code that runs in the browser (never.keys-client).

Common errors

  • 401 cms_key_invalid: wrong key, revoked key, missing feature, or Site Kit not enabled on the server. The CMS deliberately returns the same error for every reason.
  • 403 cms_origin_forbidden: the key has an origins list and the request Origin is not in it.
  • 400 cms_param_unknown: the query has a key the CMS does not accept.
  • A key limited by type: every response is private, no-store; do not put it in a shared cache.

See also

Last updated: