Compose pages through the API
Insert patterns, place components, edit a component's fields and variants, and choose a page's Layout from a script, with a dry run before each change.
Everything an editor does to compose a page can be done through the API: insert a pattern, place a component, change a placement's values or variant, choose a page's Layout, and edit a component's exposed fields and variants. A script or an agent can ask what a change would do before making it.
These routes are experimental: their requests and answers may still change before they are marked stable.
The routes are plugin routes under /admin/api/plugins/@nextlyhq/plugin-page-builder.
They run as the caller, signed in or with an API key, with the same checks as the
admin, and answer in the usual { message, item } shape. Start by reading the
manifest: it lists every id the actions take.
Read the manifest
GET /admin/api/plugins/@nextlyhq/plugin-page-builder/manifestThe manifest describes what the caller may compose with, read as the caller:
collections: where pages, patterns, components and Layouts live on this site, under the names it gave them, andcomponentField, the field a component's definition is stored in.patterns.items: each pattern'sid,title, andgranularitywhere it has one.components.items: each component'sidandtitle, with thefieldsa placement may set (id,label,type, andoptionsfor a select), theslotsit may fill, and itsvariants(idandlabel). Every component lists all three, empty where it has none.layouts.items: each Layout'sid,title, whether it ispublished, whether itisDefault, and theregionsit draws (areaandcomponentId).layouts.defaultLayoutis the site default's id. A Layout being removed is left out, since a page cannot choose it.actions: the actions below, each with itspath, everykindit takes and the JSON Schema of itsrequestbody.namedQueries: the site's named queries, each with itsname,label,description, the JSON Schema of theparamsa list may set for it, itsrows(a collection, or akeyandfields) and whether it counts itstotal. The run function is never included.
Each part says whether the caller could read it. A part whose collection the caller may
not read answers readable: false with no items, and the rest is still answered.
truncated: true means the site holds more than one read returns, under the same bounds
the editor's panels read with. ?locale=fr reads component and Layout text
in that language.
Every id a page action takes comes from here: place-component takes a component's id,
variant takes a variant's id (not its label, which can change), values is keyed by a
field's id, and set-layout takes a Layout's id. So do a definition edit's field,
slot and variant ids. An edit that points at a block inside the component (expose and
retarget-exposure) names it by its nodeId in the definition: read the component's row
from collections.components, where componentField holds the definition. The manifest's schema is published as compositionManifestSchema, so
a client can validate what it reads:
import { compositionManifestSchema } from "@nextlyhq/plugin-page-builder";
const manifest = compositionManifestSchema.parse(await response.json());
const card = manifest.components.items.find(item => item.title === "Card");
const dark = card?.variants.find(variant => variant.label === "Dark");How every action works
dryRun: trueanswers what the action would write, and whether the site would accept it, and writes nothing. The write is made as the caller and rolled back, so the site's own checks answer: field rules over the whole page, locks, component loops and the caller's rights. Why the site would refuse it is initem.refusals, empty when it would accept it. The answer shows the item as the save would store it, after the site's hooks.- Hooks run for a dry run's write too, with
context["pageBuilder.transferJudgement"]set totrue. A hook with an effect a rollback cannot undo, such as sending a message, should skip it then and act on the write that commits. item.fingerprintnames the stored item the answer was planned against. Send it back asexpectand the action applies only to that item: one that changed since answers409; plan again. An action is also refused with409when someone else saves the item between the action's read and its write.item.bysays who the action ran as:{ kind: "user", userId }, or{ kind: "api-key", userId, apiKeyId }. The item's content events, its history and the webhook and activity trails record the change the same way: against the person, or against the API key itself rather than its owner.publish: truepublishes the item with the change and needs the publish right. Without it the change is saved to the item's working draft, as the editor saves it.
An action the site refuses answers 422, with each reason in the error's
data.errors, and writes nothing.
Change a page
POST /admin/api/plugins/@nextlyhq/plugin-page-builder/pages/actions
Content-Type: application/json
{
"page": { "collection": "pages", "id": "<page id>" },
"action": { "kind": "insert-pattern", "patternId": "<pattern id>" },
"dryRun": true
}page may also name the blocks field (content by default) and, for a translated
field, the locale; a field that holds no blocks is refused. The caller needs update
on the page's collection. A collection with a Draft/Published lifecycle but no working
drafts saves an edit straight onto the published entry, so there the caller needs
publish too. action is one of:
kind | Fields | What it does |
|---|---|---|
insert-pattern | patternId, at? | Copies a published pattern's blocks into the page, as the editor's insert panel does. |
place-component | componentId, variant?, values?, at? | Places a component by reference, with a variant's id and values keyed by exposed field id. |
set-placement-values | instanceId, values?, reset? | Sets a placement's values. { "$unset": true } empties a field; reset lists fields to restore. |
choose-variant | instanceId, variant | Chooses a variant by its id, or null for the component's defaults. |
set-layout | layout, noHeaderFooter? | Chooses the page's Layout by id, or null for the site default. noHeaderFooter: true switches it off. Pages collection only. |
set-list-query | listId, query | Changes a Collection list's query: collection, relation, filters, sort, limit, offset, paginate, namedQuery. See below. |
set-conditions | nodeId, conditions | Sets a block's visibility conditions, or null to show it to everyone. See below. |
at is { "index": 2 } for the page's top level, or { "parentId", "slot", "index" }
inside a block; without it the block goes at the end of the page. The answer holds the
ops the change makes, the page's blocks as it leaves them (document) or its Layout
fields (layout), and insertedId, the new block's id for the next action to address.
New blocks get fresh ids on every write, as in the editor, so the ids in a dry run's
answer are not the ones an apply stores: address what the apply's own answer names.
set-list-query changes the query of the Collection list whose id is listId. Each part
of query is set when given, removed when null, and kept as stored when absent, so
{ "sort": "-publishedAt", "offset": null } sets the sort and stops skipping entries. The
parts are stored as the block stores them: collection is a slug; relation is
{ "of": "entry" | "item", "field" }, a to-many relation of the page's entry or of the
outer list's item; filters is a list of { "field", "op", "value" } rows an entry must
all meet, op one of equals, not_equals, greater_than, greater_than_equal,
less_than, less_than_equal, contains, in, not_in and exists, and a day written
"2026-09-01"; sort is comma-separated keys, - for descending ("-publishedAt,title");
limit is 1 to 100 and offset 0 or more; paginate: true splits the list into pages,
each at its own address (/news/page/2), and null turns that off. The write is judged as
the editor's save is: a field the collection lacks or visitors can't see, a filter on a
field holding several values, a related list nested more than one level deep, and a split
into pages the page cannot serve (a second list split into pages, one inside another list,
one of related entries, one in a component or a Layout region) are refused, in the words the
editor shows, for example This list sorts by "rating", which Posts doesn't have. Choose another field.
namedQuery is a custom source: { "name", "params" }, a named query
the site registers and a text, number or yes-or-no value for each of its inputs, replaced
whole rather than merged. It is the list's whole source, so setting it removes
collection, relation, filters and sort in the same write, and a change that sets
both is refused. Setting collection or relation removes it. A missing required input,
a value an input does not take and a query the site does not register are refused, for
example Choose a city. Upcoming events needs one to run. So is paginate: true on a list
whose query is not declared with total: true, since its pages are counted from that total.
A plugin makes the same change
through the composition service's pageAction.
set-conditions sets the visibility conditions of the block whose id is nodeId.
conditions is a list of groups, each a list of { "field", "op", "value"? }: the block
shows when every condition of any one group holds. op is one of equals, not_equals,
contains, not_contains, greater_than, less_than, exists, not_exists,
is_true and is_false, and field is one field of the page's entry, or of the list
item for a block inside a Collection list. null, or no groups, shows the block to
everyone. The devices the block shows on are kept. The write is judged as the editor's save
is: an operator the field's kind does not take, a field the entry lacks or visitors can't
see, and a value that does not fit are refused in the words the editor shows.
Change a component's definition
POST /admin/api/plugins/@nextlyhq/plugin-page-builder/components/:id/definition
Content-Type: application/json
{ "action": { "kind": "add-variant", "label": "Dark" }, "dryRun": true }Where the component store translates its definition field, an edit changes the default language's definition.
The caller needs update on components; where componentReadiness names a collection
of the site's own for them, the route edits that collection's document field and needs
update there. Each edit is held to the rules of the
component's own view: a variant's label is unique, ids are stable and never handed out
twice, a removed field's id is never reused, and a value must fit its field.
kind | Fields |
|---|---|
expose | label, nodeId, and propPath or visibility |
rename-exposure | exposureId, label |
retarget-exposure | exposureId, nodeId, and propPath or visibility |
remove-exposure | exposureId |
remove-exposed-slot | slotId |
add-variant | label |
rename-variant | variantId, label |
delete-variant | variantId |
set-variant-value | variantId, exposureId, value |
reset-variant-value | variantId, exposureId |
The answer holds the definition as the edit leaves it, targetId (the field, slot or
variant made or changed), warnings, and, when a removed field emptied variants,
prunedVariants. A refused edit answers 422 with the planner's reason as the error
code, such as label-taken.
Give a collection its template
POST /admin/api/plugins/@nextlyhq/plugin-page-builder/templates/actions
Content-Type: application/json
{ "action": { "kind": "create-template", "collection": "posts" }, "dryRun": true }A template is a builder document of kind template, stored in the page builder's
templates collection, that draws each entry of the collection it names. A collection
has one template, whatever its state: a second is refused when it is created, naming the
first by its title, or by its id to someone who may not read it.
kind | Fields | Rights on templates |
|---|---|---|
create-template | collection, and title and publish | create, and publish |
publish-template | id | read and publish |
give-entry-design | collection, entry, and title | create |
remove-entry-design | collection, entry | delete |
delete-template | id | read and delete |
A template is created as a draft unless publish is set, and named after its collection
unless title is given. A collection may have a template when it is content the admin
shows and has a slug text field, its entries' part of their address. The page
builder's own collections may not. A template's collection cannot be changed while that
collection exists. A refused action answers 409 for a collection that already has a
template and 422 for one that cannot have one; a dry run answers either as refusals.
The answer holds the template as the write stored it.
A template's lists and visibility conditions are judged against the collection it draws,
not the templates collection, so a list of the entry's related entries names that
collection's relations. A template saved inside a batch or another write's transaction
names its collection in the same write, or the save is refused, since its stored
collection cannot be read there. In the editor a template is previewed with a real entry of its
collection (Editing a template). Which
entry is previewed is the editor's own state and is not stored, so there is no action for
it.
Deleting a collection deletes its template and its entries' own designs with it, in the same transaction. The Schema Builder's delete dialog lists them first, under the page builder's name, so you see what goes before you confirm. The page builder's own collections are not affected. A template created while its collection is being deleted waits for the delete and is then refused, as for a collection that does not exist.
An entry's own design
One entry can be drawn with a design of its own instead of its collection's template.
give-entry-design copies the collection's published template into a new draft that
names the entry, so the entry keeps being drawn with the template until its own design
is published. Later changes to the template don't reach the copy. An entry has at most
one own design, held by a unique key even when two requests race. The action is refused
while the collection has no published template, and when the entry already has its own
design. The entry is read as the caller, so an entry the caller can't read answers 404.
remove-entry-design deletes it, and the entry is drawn with the template again.
Deleting an entry deletes its own design in the same transaction.
An own design is a templates document whose collection is empty and whose entry,
entryCollection and entryId name the entry it serves; forkedFrom is the template
it was copied from.
delete-template deletes a template by id: a collection's template, after which the
collection's entries without their own design are not shown as pages until it has a
published template again, or an entry's own design. Own designs are kept when their
collection's template is deleted. An own design is deleted only by a caller who may read
its entry; anyone else is answered 404, its dry run too. The dry run answers the
template it would delete.
Read a collection's own designs
GET /admin/api/plugins/@nextlyhq/plugin-page-builder/templates/entry-designs?collection=postsAnswers the collection's own designs in the list envelope, newest edit first, each as
id, entryId, title, status and updatedAt, up to 500, and only those whose
entries the caller may read. meta.hasNext says there may be more: the list was cut at
500, or the read stopped after looking through 5,000 own designs without filling it, so
treat the list as a floor then, never as the whole. Add &entry=<id> to answer that one entry's own design, or none, by its
key: ask that, not the capped list, whether an entry has one. Ask with ?template=<id>
instead to read for the collection that template draws or, for an own design, for its
entry alone.
meta carries:
| Field | What it says |
|---|---|
template | The collection's template (id, title, status), or null |
templateReadable | false when the templates were withheld from the caller, so null says nothing |
templateAllowed | Whether the collection may have a template |
mayCreateTemplate | The collection may have a template, has none, and the caller may create templates |
mayGiveDesign | The template is published and the caller may create templates |
entry | The entry asked about with &entry=, or null |
names, collection | The collection's singular and plural names, and its slug |
Everything is read as the caller. Someone who may not read the collection, or the
templates collection, is answered an empty list and no template, with
templateReadable false. An own design is listed only when the caller may read its
entry, so a collection whose read rule filters rows lists only the own designs of the
entries the caller can see.
In the admin
- The entry's Design section. Every entry whose collection has, or may have, a template shows a Design section first in its side panel: the template it is shown with and Give this post its own design, or its own design with Edit design and Remove own design…. While an own design is not published, the section says visitors still see the template. Where the collection has no published template, it says the entry isn't shown as a page, and offers the template to open or create.
- The entry list. A collection with a template gets a Design column marking each entry with its own design: Own design, or a dashed Own design · not published.
- The template. The template's side panel lists the entries with their own design, each opening its entry, and the builder's top bar shows how many there are.
- Deleting. Deleting a template from its document lists the entries with their own design, which are kept, and says the others stop being shown as pages. Deleting an entry deletes its own design with it, as its Design section says.
Other routes with a dry run
POST /save-as-patterntakesdryRun: trueand answers the pattern it would save, withrefusalssaying why the site would refuse it.- Making a Layout the default and removing one both take
dryRun, and their answers carryby. - Importing a file takes
dryRunandexpectin the same way.
Validate and plan an action yourself
The actions' schemas and planners are published from @nextlyhq/builder/ops, which
loads on a server and in a browser alike. The routes parse their bodies with the same
schemas, so an action the schema refuses is one the route refuses:
import {
definitionActionSchema,
pageActionSchema,
planDefinitionAction,
} from "@nextlyhq/builder/ops";
import { registryBlockSource } from "@nextlyhq/blocks-engine";
const action = definitionActionSchema.parse({
kind: "add-variant",
label: "Dark",
});
// The edit the route would make to this definition, or the planner's refusal.
const plan = planDefinitionAction(definition, action, {
definitions: registryBlockSource(),
});pageActionJsonSchema(), definitionActionJsonSchema() and templateActionJsonSchema()
give the same schemas as
JSON Schema, for a tool that registers them as inputs. The editor's planners are
published there too: planInsertPattern, planSaveAsPattern, planSaveAsComponent,
planExposeProperty, planAddVariant and the rest.
Call the actions from your own server code
A plugin route serving a request of its own, such as an endpoint an agent connects to,
reaches the same actions without an HTTP round trip, through the page builder's
composition service:
import {
COMPOSITION_SERVICE,
PAGE_BUILDER_PLUGIN,
type CompositionService,
} from "@nextlyhq/plugin-page-builder";
// Inside your plugin's route handler, with its `ctx`:
const composition = ctx.services.plugins[PAGE_BUILDER_PLUGIN]?.[
COMPOSITION_SERVICE
] as CompositionService;
const manifest = await composition.manifest(ctx);
await composition.templateAction(ctx, {
action: { kind: "create-template", collection: "posts" },
});
const { message, item } = await composition.pageAction(ctx, {
page: { collection: "pages", id: pageId },
action: { kind: "choose-variant", instanceId, variant: "v-dark" },
dryRun: true,
});The first argument is the route context of the request being served: each call runs as
that caller, with every check its route makes, the definition route's update right
included, and answers what the route answers. A call with no signed-in caller is refused.
Pass the context Nextly gave your handler, never one built by hand. Outside a plugin the
service is nextly.plugins["@nextlyhq/plugin-page-builder"].composition.
Move patterns, components and Layouts between sites
Export an item with everything it depends on as one file, and import it into another site after a preview.
Named queries
Give a Collection list a custom source written in code, with typed inputs authors fill in, that reads only what it declares and only what visitors may see.