Browse the docs Open Close
Editor documents
The draft behind the template.
An editor document is the v2 draft of a template: its layers, its groups and every design-time property the editor shows. A template renders from that draft, so a change here changes what the next render draws.
Every write is a compare-and-swap. Read the document, keep the `revision` it returns, and send that revision back. If the stored revision moved, the write returns `409` with the current revision and the current document. Rebuild the change on top of them and send the write again. Never resend the same body with the returned revision.
`PATCH` applies a closed list of operations and changes only the properties you name. `PUT` replaces the whole document and drops every property you leave out. `GET /v1/guides/editor-document` carries the constraints both accept.
On this page
/v1/templates/{templateUuid}/document
Get the editor document
Returns the stored v2 editor document and its revision. A template with no draft returns a null document and revision 0. Read this before every write.
Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
templateUuid |
path | string | Yes | UUID of the template. |
The read gate and the write gate name the same people. Every account in your company that can write the document can also read it.
Example request
curl
curl https://snapsbrew.com/api/v1/templates/<uuid>/document \
-H 'Authorization: Bearer <your-token>'
Example responses
{
"document": {
"version": 2,
"layers": [
{
"key": "headline",
"type": "text",
"properties": [
{
"name": "fontWeight",
"value": 700
}
]
}
],
"groups": []
},
"revision": 4
}
{
"message": "This action is unauthorized."
}
{
"message": "Not found."
}
/v1/templates/{templateUuid}/document
Apply editor operations
Applies a closed list of layer operations and saves the result under the next revision. `set_layer_property` takes `layer_key`, `property` and `value`. `set_layer_type` takes `layer_key` and `type`. Every operation in one call applies together, or none of them applies.
Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
templateUuid |
path | string | Yes | UUID of the template. |
Request body
Content-Type: application/json
| Field | Type | Required | Validation | Description |
|---|---|---|---|---|
revision |
integer | Yes | required|integer|min:0 |
The revision the last read returned. |
operations |
array | Yes | required|array|max:100 |
One to 100 operation objects, applied in order. |
A rejected operation returns a stable `code`, for example `editor_operation_layer_not_found` or `editor_operation_invalid_value`. Correct the operation and call again.
A malformed body returns the standard validation shape instead, with a message under `errors.revision` or `errors.operations`.
The route allows 30 calls a minute for one token and 180 a minute for one company.
Example request
curl
curl -X PATCH https://snapsbrew.com/api/v1/templates/<uuid>/document \
-H 'Authorization: Bearer <your-token>' \
-H 'Content-Type: application/json' \
-d '{"revision":4,"operations":[{"operation":"set_layer_property","layer_key":"headline","property":"fontWeight","value":700}]}'
Example responses
{
"document": {
"version": 2,
"layers": [
{
"key": "headline",
"type": "text",
"properties": [
{
"name": "fontWeight",
"value": 700
}
]
}
],
"groups": []
},
"revision": 5
}
{
"code": "editor_document_conflict",
"current_revision": 5,
"current_document": {
"version": 2,
"layers": [],
"groups": []
}
}
{
"code": "editor_operation_layer_not_found"
}
/v1/templates/{templateUuid}/document
Replace the editor document
Replaces the whole v2 editor document and saves it under the next revision. Send the document you read, with your change applied to it. Any layer or property you leave out is gone. Prefer `PATCH` unless you rebuild the document.
Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
templateUuid |
path | string | Yes | UUID of the template. |
Request body
Content-Type: application/json
| Field | Type | Required | Validation | Description |
|---|---|---|---|---|
revision |
integer | Yes | required|integer|min:0 |
The revision the last read returned. |
document |
object | Yes | required|array |
The complete v2 document, with `layers` and `groups`. |
The document is bounded: 262144 bytes, 1000 nodes, depth 12, and 16384 characters for one string. A document over a limit returns `editor_document_too_large` or `editor_document_budget_exceeded` under `errors.document`.
The route allows 30 calls a minute for one token and 180 a minute for one company.
Example request
curl
curl -X PUT https://snapsbrew.com/api/v1/templates/<uuid>/document \
-H 'Authorization: Bearer <your-token>' \
-H 'Content-Type: application/json' \
-d '{"revision":4,"document":{"version":2,"layers":[],"groups":[]}}'
Example responses
{
"document": {
"version": 2,
"layers": [],
"groups": []
},
"revision": 5
}
{
"code": "editor_document_conflict",
"current_revision": 5,
"current_document": {
"version": 2,
"layers": [],
"groups": []
}
}
{
"message": "The given data was invalid.",
"errors": {
"document": [
"editor_document_too_large"
]
}
}
/v1/templates/{templateUuid}/document/preflight
Inspect the editor document
Reads the stored document and returns the known draft problems it carries, each with a code, a JSON pointer and a message. An empty `issues` list means the known checks pass. It does not guarantee that the render looks right.
Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
templateUuid |
path | string | Yes | UUID of the template. |
Run it after the last write and before you publish the template.
Example request
curl
curl https://snapsbrew.com/api/v1/templates/<uuid>/document/preflight \
-H 'Authorization: Bearer <your-token>'
Example responses
{
"issues": [
{
"code": "image_asset_missing",
"path": "/layers/0/source",
"message": "Image layers require a pinned asset id."
}
],
"revision": 4
}
{
"message": "This action is unauthorized."
}
{
"message": "Not found."
}