Skip to content

Edit body blocks

Updates, inserts, moves or deletes blocks of a body by id, without sending it whole. `getBodySchema` answers the props each block takes.

Needs the file:write scope.

Rich text (edits[].block) is HTML in a closed format: p, h1 to h3, br, strong, em, u, s, sup, sub, code, a (href), span (style color, background-color), text-align on p and h1 to h3, ul, ol, li (data-checked), table rows and cells, pre with code, blockquote, hr, details with summary, figure with figcaption, and for images, videos, audio, slideshows, formulas, diagrams and other blocks, their props as getBodySchema lists them; anything else is refused with its path and reason. E.g.

Intro

Read this first.

Set text_format to “markdown” to write Markdown instead.

Call

  • Tool: edit_body
  • Scope: file:write
  • Writes, and may change or remove what is there.
  • Acts on a store.

Arguments

Name Type Required Description
store string No The store to act on.
text_format "html" or "markdown" No The format the rich text fields are written in: the rich text format’s HTML, or Markdown converted into it before it is validated. A text already stored in the format (starting with <rich-text) is kept as it is either way.
target object Yes
full true No Answers the texts, attachments and file lists the short answer leaves out.
from object or null Yes The asset.id the body (or the staged body) held when the caller read it, never its attachment.id; null for a first staged body, which the edits start from the live one.
staged boolean No Edits the unpublished next body instead of the live one.
live object or null No On a first staged edit, the live body’s asset.id the edits start from, never its attachment.id.
unpublished true No On a live edit, the caller made it believing its page or product isn’t live.
edits array of object Yes The edits, applied in order, landing together or not at all.
{
  "type": "object",
  "properties": {
    "store": {
      "type": "string",
      "description": "The store to act on."
    },
    "text_format": {
      "type": "string",
      "enum": [
        "html",
        "markdown"
      ],
      "default": "html",
      "description": "The format the rich text fields are written in: the rich text format’s HTML, or Markdown converted into it before it is validated. A text already stored in the format (starting with `<rich-text`) is kept as it is either way."
    },
    "target": {
      "type": "object",
      "properties": {
        "kind": {
          "type": "string",
          "enum": [
            "product",
            "entry",
            "store",
            "page"
          ]
        },
        "id": {
          "description": "Required but for the store's home, which takes the store's own id or none.",
          "type": "string",
          "minLength": 1,
          "maxLength": 512
        }
      },
      "required": [
        "kind"
      ],
      "additionalProperties": false
    },
    "full": {
      "description": "Answers the texts, attachments and file lists the short answer leaves out.",
      "type": "boolean",
      "const": true
    },
    "from": {
      "description": "The `asset.id` the body (or the staged body) held when the caller read it, never its `attachment.id`; null for a first staged body, which the edits start from the live one.",
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 512
            }
          },
          "required": [
            "id"
          ],
          "additionalProperties": false
        },
        {
          "type": "null"
        }
      ]
    },
    "staged": {
      "description": "Edits the unpublished next body instead of the live one.",
      "type": "boolean"
    },
    "live": {
      "description": "On a first staged edit, the live body's `asset.id` the edits start from, never its `attachment.id`.",
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 512
            }
          },
          "required": [
            "id"
          ],
          "additionalProperties": false
        },
        {
          "type": "null"
        }
      ]
    },
    "unpublished": {
      "description": "On a live edit, the caller made it believing its page or product isn't live.",
      "type": "boolean",
      "const": true
    },
    "edits": {
      "description": "The edits, applied in order, landing together or not at all.",
      "type": "array",
      "items": {
        "anyOf": [
          {
            "type": "object",
            "properties": {
              "kind": {
                "description": "Sets the block's props, or replaces the block with `replace`; its id stays.",
                "type": "string",
                "const": "update"
              },
              "id": {
                "description": "The block's id, as `readBody`'s content holds it.",
                "type": "string",
                "minLength": 1,
                "maxLength": 512
              },
              "block": {
                "description": "The props to set as a JSON object with the block's `type`, a `null` one removed; with `replace`, the whole block, of any type. A block it holds with no `id` takes a new one. Its texts are rich texts; an image it starts showing is at most 15 MB.",
                "type": "string",
                "x-rich-text": "body",
                "minLength": 2,
                "maxLength": 262144
              },
              "replace": {
                "description": "Replaces the whole block instead of setting the props given.",
                "type": "boolean",
                "const": true
              }
            },
            "required": [
              "kind",
              "id",
              "block"
            ],
            "additionalProperties": false
          },
          {
            "type": "object",
            "properties": {
              "kind": {
                "description": "Adds a block.",
                "type": "string",
                "const": "insert"
              },
              "block": {
                "description": "The block as a JSON object; one with no `id` takes a new one, which the write answers, as does each block it holds with none. Its texts are rich texts; an image it starts showing is at most 15 MB.",
                "type": "string",
                "x-rich-text": "body",
                "minLength": 2,
                "maxLength": 262144
              },
              "after": {
                "description": "The block it goes after, in the list that holds that block.",
                "type": "string",
                "minLength": 1,
                "maxLength": 512
              },
              "at": {
                "description": "The start or end of the body's top-level blocks, when it names no block to follow; on a product page, a block that is no column starts after its columns.",
                "type": "string",
                "enum": [
                  "start",
                  "end"
                ]
              }
            },
            "required": [
              "kind",
              "block"
            ],
            "additionalProperties": false
          },
          {
            "type": "object",
            "properties": {
              "kind": {
                "description": "Moves a block, with what it holds.",
                "type": "string",
                "const": "move"
              },
              "id": {
                "description": "The block's id, as `readBody`'s content holds it.",
                "type": "string",
                "minLength": 1,
                "maxLength": 512
              },
              "after": {
                "description": "The block it goes after, in the list that holds that block.",
                "type": "string",
                "minLength": 1,
                "maxLength": 512
              },
              "at": {
                "description": "The start or end of the body's top-level blocks, when it names no block to follow; on a product page, a block that is no column starts after its columns.",
                "type": "string",
                "enum": [
                  "start",
                  "end"
                ]
              }
            },
            "required": [
              "kind",
              "id"
            ],
            "additionalProperties": false
          },
          {
            "type": "object",
            "properties": {
              "kind": {
                "description": "Removes a block, with what it holds.",
                "type": "string",
                "const": "delete"
              },
              "id": {
                "description": "The block's id, as `readBody`'s content holds it.",
                "type": "string",
                "minLength": 1,
                "maxLength": 512
              }
            },
            "required": [
              "kind",
              "id"
            ],
            "additionalProperties": false
          }
        ]
      },
      "minItems": 1,
      "maxItems": 100
    }
  },
  "required": [
    "target",
    "from",
    "edits"
  ],
  "additionalProperties": false
}

Answer

Name Type Required Description
blocks array of string Yes
attachment object Yes
asset object Yes The asset the body holds now: the next write’s from (or a staged write’s live).
created array of object Yes The attachments the write bound: the embeds a live write or a publish derived.
attachments array of object No Every attachment on the target with its asset whole; answered only with full.
preview object or null Yes The body’s page on the store with a token opening it, for an hour; null where none is answered.

The answer’s full shape is on its API reference page.

Errors

A refused call is a tool error. Its structuredContent holds a code and its context, except for client-fault. This tool may answer:

  • invalid: an argument is malformed; context.path names it.
  • invalid at ["store"]: store is missing while the connection reaches more than one store, or names a store it doesn’t reach.
  • not_found: nothing matches a reference given.
  • conflict: the call clashes with the current state; context names the field and, where it helps, its current value, and for a from, live, expect or version that no longer matches, the argument (path) and what it takes (reason).
  • not_permitted: this connection may not make this call. When context.reason is limit, too many calls: retry_after says when to try again.
  • internal or unavailable: the call failed inside Sherpo, and the write may have landed. This write takes no idempotency key, so read the state back before trying again.
  • client-fault: the server failed around the call. core_answer ok means the write landed, so don’t send it again. When reached_core is false, nothing happened and the call may be made again. Otherwise, this write takes no idempotency key, so read the state back before trying again.
  • HTTP 403 with insufficient_scope: the connection lacks the scope this tool needs.
  • HTTP 401 with invalid_token: the access token expired or the connection ended. Refresh the token, and connect again if the refresh fails or the new token is refused too.

Any other code may come back too, such as a conflict when the state changed under the call. When the answer was already streaming, a 401 or 403 comes back as a tool error with only its text. See Errors for every code and its context.

Type to search…

↑↓ navigate↵ selectEsc close