apply_ops
Applies a list of edits to a file as one change. Every op runs in order and they are saved together, or none of them is.
What it does
Use apply_ops for any change bigger than one edit. The batch is one undo step in Wonderblok. If any op fails, nothing is written. Each op is an object with an op field, and an unknown field in an op is refused.
- insert
- node, plus optional parent, board, index, ref and copy. Adds a layer.
- upsert
- node with a key, plus optional parent, board, ref and prune. Adds the layer, or updates the one with that key in that place and keeps its ids.
- update
- id and patch. Sets properties on a layer. A null value removes a property.
- move
- id, plus optional parent, board, index, x, y and group.
- delete
- id. Removes a layer and everything inside it.
- set_token
- name and token. The token is an object with type and value, or null to remove an unused token.
Give an insert or upsert a ref, and later ops in the same call can write @name in place of an id or a parent. More ops exist, among them duplicate, rename_token, replace_text, set_font and snap_to_tokens. Ask read_guide for the topic editing to see them.
Arguments
- guidelines
- The hash from get_guidelines. Without the current hash the call is refused and nothing is written.
- ops
- The array of ops. Give this or from_file, not both.
- from_file
- Path of a JSON file holding the ops array, for a payload too big to send in the call.
- verbose
- true returns every op's full result. The default is false: refs and ids only.
- dry_run
- true checks the ops, including the guidelines gate and lint, and replies as if applied without saving.
- if_revision
- The revision you last read. The write is refused if the file has changed since.
- opsId
- With edits, instead of ops: the id a refused call returned.
- edits
- With opsId: a list of {find, replace} fixes to the refused ops.
- file
- Optional. The file to edit, by name or path. Leave it out when only one file is open.
What it returns
Compact JSON. The default reply has node.ids, one entry per op, and node.refs, which maps each ref to the id it got. It also has revision, snapped and warnings. A hex color that equals a token is snapped to it and listed in snapped. Any other hex color, and any color or font that is not a token, is rejected. Entries from the ops themselves are prefixed with the op number, like ops[0]:.
Warnings also list rules your touched screens break, as lines that start with guideline:, and any change the person made in Wonderblok since your last call. A dry run replies with dryRun and a report, and saves nothing.
Example
apply_ops { "guidelines": "9c1e0b7a42d3f860", "ops": [ { "op": "insert", "node": { "type": "frame", "name": "Big", "width": 390, "height": 844 }, "ref": "big" }, { "op": "insert", "parent": "@big", "node": { "type": "text", "name": "T", "content": "hello", "fill": "$ink" } } ]}{ "node": { "ids": ["…", "…"], "refs": { "big": "…" } }, "revision": …, "snapped": [], "warnings": [ … ]}If an op fails, the call is an error and nothing is saved. The reply names the op and keeps the batch under an id.
// apply_ops { "guidelines": "…", "ops": [{ "op": "update", "id": "hfsuX", "patch": { "fill": "#123456" } }] }ops[0]: … (nothing was applied)opsId: ops-1. To fix, call apply_ops {opsId: "ops-1", edits: [{find, replace}]} instead of sending the ops again.apply_ops { "guidelines": "…", "opsId": "ops-1", "edits": [{ "find": "#123456", "replace": "$ink" }] }Notes
- Each find in edits must match exactly once in the ops as compact JSON, with no spaces after a colon or a comma, and with keys in alphabetical order, because the server re-serializes them. The server keeps the refused ops in memory, so after a restart you send them again.
- A missing or old hash is refused, whatever the ops are. Read the rules again with get_guidelines and pass the new hash.
- Colors and fonts must be tokens. See Tokens and guidelines.
- To bring in a whole page of HTML at once, use write_page.
Was this page helpful?
Edited Nov 8, 2026