PUT

Update a document

Replace a template’s content, guarded by the revision you read.

View as Markdown
PUThttps://api.muzekit.com/v1/templates/{id}/document
curl -X PUT https://api.muzekit.com/v1/templates/tpl_Vk1t4l9xvQv/document \
  -H "Authorization: Bearer $MUZEKIT_SECRET_KEY" \
  -H 'If-Match: "3"' \
  -H "Content-Type: application/json" \
  -d @document.json

{id} is the template's tpl_… id or its key. In the cURL example, document.json holds { "document": { … } }.

Headers

If-Matchstring

The revision you edited, e.g. "3". Required unless the body has revision.

Body

documentobjectrequired

The full document: pages, and optional meta and ext.

revisionnumber

The revision you edited, for clients that can't set If-Match. If-Match wins when both are sent.

Send the revision once: in If-Match, or as revision in the body (3, or the string "3"). With neither the save answers 428 if_match_required; a revision that isn't a whole number answers 400.

A save replaces the current version in place: it doesn't add a version, and the old content is gone. Duplicate the template first if you want to keep it. Every save sends a template.updated webhook, and renders the template when render on save is on.

Examples

Change a text layer's words

Read the document, change the layer's content, and save with the revision you read. Here the layer is the one whose field key is headline.

URL=https://api.muzekit.com/v1/templates/product-card/document
AUTH="Authorization: Bearer $MUZEKIT_SECRET_KEY"

curl -s "$URL" -H "$AUTH" > current.json
REV=$(jq '.revision' current.json)

jq '{ document: .document }
  | (.document.pages[].elements[] | select(.parameterId == "headline")
    | .content) = "Winter sale"' current.json \
  | curl -X PUT "$URL" -H "$AUTH" -H "If-Match: \"$REV\"" \
      -H "Content-Type: application/json" -d @-

To change a value for one render only, send it in modifications when you render; the template stays as it is.

Send the revision in the body

Some clients, such as an AI agent's HTTP tool, can't set headers. Put the revision you read next to the document instead.

curl -X PUT https://api.muzekit.com/v1/templates/product-card/document \
  -H "Authorization: Bearer $MUZEKIT_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "revision": 3, "document": { "pages": [ … ] } }'

Retry when someone saved first

A user may save in the editor between your read and your write. Then the save answers 409 revision_conflict: read again, apply your change to the new document, and save again.

# A 409 means: run the read and the change again
curl -s -o /dev/null -w "%{http_code}\n" -X PUT \
  https://api.muzekit.com/v1/templates/product-card/document \
  -H "Authorization: Bearer $MUZEKIT_SECRET_KEY" \
  -H 'If-Match: "3"' \
  -H "Content-Type: application/json" \
  -d @document.json

Copy one template's design into another

Read the source's document, read the target's revision, and save the source's document over the target. The target keeps its id, key and name, so renders and sessions that name it now get the new design.

API=https://api.muzekit.com/v1
AUTH="Authorization: Bearer $MUZEKIT_SECRET_KEY"

REV=$(curl -s "$API/templates/product-card/document" -H "$AUTH" | jq '.revision')

curl -s "$API/templates/product-card-draft/document" -H "$AUTH" \
  | jq '{ document }' \
  | curl -X PUT "$API/templates/product-card/document" -H "$AUTH" \
      -H "If-Match: \"$REV\"" -H "Content-Type: application/json" -d @-

The source can be in another environment: read it with that environment's key. To make a new template from a document instead, see Get a document.

Response

JSON
{
  "object": "document",
  "template": "tpl_Vk1t4l9xvQv",
  "version": "ver_Lp0sQ7dXk2m",
  "revision": 4
}

The ETag header carries the new revision. Send it as If-Match on your next save.

ErrorWhen
409 revision_conflictSomeone saved since you read it: fetch the document again and reapply your change
428 if_match_requiredThe request has no If-Match
400 invalid_documentThe document breaks a rule; problems lists every one
404 template_not_foundNo template with this id or key in this environment