Document Command API
/api/2026-03/documents/{documentId}/commandsRequest Body
JSON BodySent as JSON in the request body.
| Parameter | Type | Description |
version | integer | Current document version. When set on update the version is checked. |
preconditions | array | An array of preconditions for command execution. If a precondition assertion fails, no commands are executed and the request responds with a Each entry is an object with at least a type property. Possible types:
See further details in example requests. |
preserveUpdatedAt | boolean | When set to When combined with a This is useful for imports and migrations where the original timestamps should be preserved (added in release-2026-03) |
commands* | array | An array of commands to execute. Each entry is an object with at least an operation property. Command API operations Possible operations:
Some commands supports an optional See further details in example requests. |
Description
Execute a Document Command based on its id.
All commands run in a single transaction.
Responses
Concepts
The Document Command API lets you modify documents by sending an array of commands in a single PATCH request. All commands in a request are executed sequentially within a single transaction. If any command fails, the entire batch is rolled back and no changes are persisted.
Each command is an object with an operation property that determines its type. The commands array can contain any combination of operations, with the constraint that publish, unpublish, and addPublishSchedule must be the last command and are mutually exclusive.
Versioning and Conflict Detection
There are two mechanisms to prevent concurrent modifications from overwriting each other:
Document version: Pass the version parameter (an integer) in the request body. The server checks that this matches the current document version before executing commands. If another user modified the document since you last read it, you receive a 409 Conflict response with expectedVersion and currentVersion in the error details.
Old value checks: Individual commands that modify a value support an optional oldValue parameter. When provided, the server verifies the current value matches oldValue before applying the change. This is more granular than version checking and useful when you only care about a specific field. If the value has changed, the server returns a 409 Conflict response. Using oldValue is redundant when you also provide a document version.
Preconditions
Preconditions are assertions checked before any commands execute. If a precondition fails, the server responds with 409 Conflict and no commands run.
| Type | Description |
|---|---|
isPublished | Asserts the document's publication state matches the value boolean. Set value: true to require the document is published, value: false to require it is unpublished. |
isPublishedAndHasNoChanges | Asserts the document is published and the draft has no changes since the last publication. No additional properties required. |
{
"preconditions": [
{"type": "isPublished", "value": true}
],
"commands": [...]
}
Commands Overview
All 18 operations are grouped into three categories:
Content Commands
Commands that modify the document content tree (the livingdoc). See Content Commands for full details.
| Operation | Description |
|---|---|
insertComponent | Insert a new component at a specified position |
removeComponent | Remove a component from the document |
setEditableDirective | Set text content in an editable directive |
setIncludeDirective | Configure include directive params and overrides |
setLinkDirective | Set link href, target, and document references |
setStyleDirective | Set a style property on a style directive |
setComponentStyle | Set a style property directly on a component |
setComponentCondition | Set conditional display logic (dateTime, brands) |
Metadata Commands
Commands that modify document metadata. See Metadata Commands for full details.
| Operation | Description |
|---|---|
setTitle | Set the document title |
setMetadataProperty | Update any metadata property by name |
Publishing & Scheduling Commands
Commands for publication lifecycle management. See Publishing & Scheduling Commands for full details.
| Operation | Description |
|---|---|
publish | Create a new publication |
unpublish | Unpublish the document |
setEmbargo | Set an embargo with optional reason and expiry |
removeEmbargo | Remove an embargo |
addPublishSchedule | Schedule future publication |
cancelPublishSchedule | Cancel a scheduled publication |
addUnpublishSchedule | Schedule future unpublication |
cancelUnpublishSchedule | Cancel a scheduled unpublication |
Error Handling
400 Bad Request
Returned when a command fails validation. The response includes commandIndex indicating which command (zero-based) failed, along with a descriptive message.
{
"status": 400,
"error": "Bad Request",
"error_details": {
"message": "Command at index 0 failed: Metadata property \"title\" does not exist",
"commandIndex": 0
}
}
Schema validation errors (e.g. invalid operation names or missing required properties) return a different format without commandIndex:
{
"status": 400,
"error": "Bad Request",
"error_details": {
"commands.0": "value of tag \"operation\" must be in oneOf"
}
}
404 Not Found
Returned when the document specified by documentId does not exist.
409 Conflict
Returned when:
- The document
versiondoes not match (concurrent modification) - A
preconditionassertion fails - An
oldValuecheck fails on a specific command
{
"status": 409,
"error": "Conflict",
"error_details": {
"name": "Conflict",
"message": "The document you tried to update is outdated",
"expectedVersion": 1,
"currentVersion": 2
}
}
Related
- Authentication -- How to authenticate API requests
- API Versioning -- API version format and constraints
- Document Object -- Document structure reference
- Errors -- Error response format
- Latest Draft -- Retrieve the current draft to get component IDs and metadata values