⚠️ Work in progress — createCMS is pre-1.0 and not production-ready (not tested in production). Expect breaking changes.
createCMS
Reference

Server API

The type-safe server-side API on cms.api, method by method.

createCMS returns an api object namespaced by collection: cms.api.<collection>.<method>. Methods follow the better-call convention: read methods take a query object, write methods take a body object. Inputs and outputs are typed from your collection definitions.

const { roots } = await cms.api.pages.listRoots({ query: { limit: 20 } });

The same methods are available on the client, with identical types.

Collection methods

listRoots

Lists the entries (roots) of a collection. GET, input via query (all fields optional).

Query fieldTypeDefaultDescription
limitnumber20Page size (1 to 100).
offsetnumber0Rows to skip.
searchstringSearch term.
searchFieldcolumn or propertyField to search.
sortBycolumn or propertycreatedAtSort field.
sortDirection'asc' | 'desc'descSort order.
filterFieldcolumn or propertyField to filter.
filterValuestringFilter value.
hasPublicationsbooleanOnly entries with or without publications.
createdAfterDateEntries created after this time.
createdBeforeDateEntries created before this time.
parentRootIdstringFilter by parent entry.

Returns { roots, total, hasMore }. Each root has rootId, createdAt, createdBy, parentRootId, sortOrder, slug, properties (typed), hasPublications, publicationCount, branchCount, and openMergeRequestCount. path (the full ancestor-resolved URL) is present only for slug-enabled collections, and createdByUser only when called with query.withUser.

createRoot

Creates a new entry. POST, input via body.

Body fieldTypeRequiredDefaultDescription
propertiestyped root propertiesyes if the root has required propsThe root's properties.
slugstringnoSlug for the entry.
parentRootIdstringnoParent entry for nesting.
messagestringno'Initial commit'Commit message.

Returns { rootId, branchId, commitId }.

const { rootId } = await cms.api.pages.createRoot({
  body: { slug: 'welcome', properties: { title: 'Welcome' } },
});

getBlockTree

Returns the editing view of an entry's block tree. GET, input via query.

Query fieldTypeRequiredDescription
rootIdstringyesThe entry.
branchIdstringyesThe branch to read.
commitIdstringnoA specific commit (defaults to branch head).
rawbooleannoKeep stored values for editing: skip variable, link, and image resolution.
includeReferencePreviewsbooleannoAlso return a references sidecar (see below).

Returns { tree, reconstructed }. The tree is a discriminated union over type, and the top node is type: 'root'.

With includeReferencePreviews: true, the result also carries references: a Record<storedReferenceValue, tree> holding the published render tree of every reference embedded anywhere in the entry — its own nested references resolved and {{variables}} substituted, resolved through the active scope (tenant / language fallback). This lets an editor render the raw editable tree and all embedded reusable-block previews in one call instead of one getPublishedContent per reference. References that are not published (or out of scope) are omitted from the map. The flag is opt-in because resolving is more expensive; combine it with raw: true to keep the main tree editable while still getting rendered previews.

createBlock

Adds a block under a parent. POST, input via body.

Body fieldTypeRequiredDescription
rootIdstringyesThe entry.
branchIdstringyesThe branch.
parentBlockIdstringyesParent block to attach under.
typeblock type nameyesOne of the collection's block types.
propertiestyped block propertiesyesThe block's properties.
positionnumbernoInsert position (defaults to append).
messagestringnoCommit message.

Returns { commitId, blockId }.

updateBlock

Updates a block with patch semantics: supplied fields overwrite, omitted fields stay, null deletes. POST, input via body.

Body fieldTypeRequiredDescription
rootIdstringyesThe entry.
branchIdstringyesThe branch.
blockIdstringyesThe block to update.
typeblock type nameyesThe block's type.
propertiespartial block propertiesyesFields to change.
messagestringnoCommit message.

Returns { commitId }.

getPublishedContent

Returns the published view of an entry, with references resolved. GET, input via query. Provide at least one of rootId, slug, or path.

Query fieldTypeDescription
rootIdstringLook up by entry id.
slugstringLook up by slug (slug-enabled collections).
pathstringLook up by full path.
rawbooleanKeep stored values: skip variable and link resolution.

Returns { rootId, collection, variants }, where each variant has branchId, branchName, commitId, publishedAt, publishedBy, and a resolved tree. Additional fields appear when relevant: a page-level A/B test descriptor when one is running, and ancestors when the collection uses nested slugs.

In the resolved tree, reference properties are inlined and link properties become a ResolvedLink (an href). An image property is returned verbatim as the stored asset-id string (nothing is resolved); build the gate URL /media/asset/{id} from that id to serve it. A raw read keeps the stored link / reference target instead, for re-picking in an editor.

const { variants } = await cms.api.pages.getPublishedContent({
  query: { path: '/welcome' },
});

listBranches

Lists the branches of an entry. GET, input via query.

Query fieldTypeDefaultDescription
rootIdstringThe entry (required).
limitnumber20Page size (1 to 100).
offsetnumber0Rows to skip.
searchstringSearch term.
isDeletablebooleanFilter protected vs deletable branches.
hasPublicationsbooleanFilter by publication state.
hasOpenMergeRequestsbooleanFilter by open merge requests.

Returns { branches, total, hasMore }. Each branch has id, rootId, name, headCommitId, createdBy, createdAt, updatedAt, isDeletable, and hasPublications (whether the branch is currently published) — plus createdByUser when called with query.withUser.

createBranch

Creates a branch from an existing one, copying its head commit. POST, input via body.

Body fieldTypeRequiredDescription
rootIdstringyesThe entry.
namestringyesBranch name (unique per entry).
sourceBranchIdstringyesBranch to copy the head commit from.
createdBystringnoActor (defaults to the request user).

Returns { branchId, headCommitId }.

getBranch

Returns one branch. GET, query: { branchId }.

renameBranch

Renames a branch (main cannot be renamed). POST, body: { branchId, newName }.

deleteBranch

Deletes a branch. main, published branches, and branches with open merge requests cannot be deleted. POST, body: { branchId }.

publishBranch

Publishes a branch as the live content of an entry. POST, input via body.

Body fieldTypeRequiredDescription
rootIdstringyesThe entry.
branchIdstringyesThe branch to publish.
publishedBystringnoFallback actor, used only when the request has no user. The request user takes precedence.

Returns { rootId, branchId, commitId, publishedBy, publishedAt }.

Admin methods

System-wide methods live under cms.api.admin.

admin.runPruning

Runs one bounded, resumable pruning pass to reclaim storage (old commits, hard-deleted archived roots, unreferenced assets). Requires dataRetention to be configured. POST, input via body.

Body fieldTypeDefaultDescription
dryRunbooleanfalsePlan deletions without persisting.
maxRootsnumber50Roots processed per pass (1 to 1000).
maxDurationMsnumber8000Soft time budget in milliseconds.
liveRescanMsnumber86400000Interval before a live root is rescanned.
maxAssetsnumber100Archived assets reclaimed per pass (1 to 1000).

Returns deletion counts (deletedCommits, deletedBlockVersions, deletedSnapshots, deletedMergeRequests, deletedApprovals), deletedRoots and deletedAssets (id arrays), prunedRoots, processedLiveRoots, plugins, stoppedReason, and done (true when all due work has drained within budget).

admin.reindexSearch

Rebuilds the full-text search index across all entities. POST, empty body. Returns { indexed } with per-entity counts.

More collection methods

Each collection also exposes the rest of the versioning and review surface. The remaining methods, all under cms.api.<collection>:

  • Blocks: moveBlock, deleteBlock, duplicateBlock, updateBlocks, updateRoot.
  • Branches: revertBranch, checkDivergence (plus the branch methods above).
  • Merges: createMergeRequest, getDiff, checkConflicts, resolveConflicts, createMergeBlockVersion, executeMerge, listMergeRequests, updateMergeRequest, closeMergeRequest, reopenMergeRequest.
  • Approvals: requestApproval, approve, reject, cancelApproval, getApproval, listApprovals.
  • Comments: createCommentThread, createCommentMessage, listCommentThreads, getCommentThread, resolveCommentThread, reopenCommentThread, updateCommentMessage, deleteCommentMessage, listMentions.
  • Publications: unpublishBranch, listPublications (plus publishBranch and getPublishedContent).
  • Redirects: createRedirect, updateRedirect, archiveRedirect, listRedirects, and resolveRedirect (call this in routing to follow a redirect).

Other namespaces

Beyond collections and admin, cms.api exposes system namespaces, each on its own page:

These methods are also available on the client as client.<collection>.<method> and client.admin.<method>.

On this page