Skip to main content
Alpha: Document API is currently alpha and subject to breaking changes.

Summary

Insert content into the document. Two input shapes: legacy string-based (value + type) inserts inline content at a text position within an existing block; structural SDFragment (content) inserts one or more blocks as siblings relative to a BlockNodeAddress target. When target is omitted, content appends at the end of the document. Legacy mode supports text (default), markdown, and html content types via the type field. Structural mode uses placement (before/after/insideStart/insideEnd) to position relative to the target block.
  • Operation ID: insert
  • API member path: editor.doc.insert(...)
  • Mutates document: yes
  • Idempotency: non-idempotent
  • Supports tracked mode: yes
  • Supports dry run: yes
  • Deterministic target resolution: yes

Expected result

Returns an SDMutationReceipt with applied status; resolution reports a TextAddress for legacy text insertion or a BlockNodeAddress for structural insertion. Receipt reports NO_OP if the insertion point is invalid or content is empty.

Input fields

Variant 1 (target.kind=“text”)

FieldTypeRequiredDescription
targetTextAddressnoTextAddress
target.blockIdstringno
target.kind"text"noConstant: "text"
target.rangeRangenoRange
target.range.endintegerno
target.range.startintegerno
typeenumno"text", "markdown", "html"
valuestringyes

Variant 2 (target.kind=“block”)

FieldTypeRequiredDescription
contentobject \object[]yesOne of: object, object[]
nestingPolicyobjectno
nestingPolicy.tablesenumno"forbid", "allow"
placementenumno"before", "after", "insideStart", "insideEnd"
targetBlockNodeAddressnoBlockNodeAddress
target.kind"block"noConstant: "block"
target.nodeIdstringno
target.nodeTypeenumno"paragraph", "heading", "listItem", "table", "tableRow", "tableCell", "tableOfContents", "image", "sdt"

Example request

{
  "content": {
    "content": [
      {
        "text": "example",
        "type": "text"
      }
    ],
    "type": "paragraph"
  },
  "placement": "after",
  "target": {
    "kind": "block",
    "nodeId": "node-def456",
    "nodeType": "paragraph"
  }
}

Output fields

Variant 1 (success=true)

FieldTypeRequiredDescription
evaluatedRevisionobjectno
evaluatedRevision.afterstringno
evaluatedRevision.beforestringno
resolutionobjectno
resolution.rangeTextMutationRangenoTextMutationRange
resolution.range.fromintegerno
resolution.range.tointegerno
resolution.selectionTargetSelectionTargetnoSelectionTarget
resolution.selectionTarget.endSelectionPointnoSelectionPoint
resolution.selectionTarget.kind"selection"noConstant: "selection"
resolution.selectionTarget.startSelectionPointnoSelectionPoint
resolution.targetTextAddress \BlockNodeAddressnoOne of: TextAddress, BlockNodeAddress
successtrueyesConstant: true

Variant 2 (success=false)

FieldTypeRequiredDescription
evaluatedRevisionobjectno
evaluatedRevision.afterstringno
evaluatedRevision.beforestringno
failureobjectyes
failure.codeenumyes"INVALID_TARGET", "NO_OP", "CAPABILITY_UNAVAILABLE", "UNSUPPORTED_ENVIRONMENT", "INVALID_NESTING", "INVALID_PLACEMENT", "INVALID_PAYLOAD", "CAPABILITY_UNSUPPORTED", "ADDRESS_STALE", "DUPLICATE_ID", "INVALID_CONTEXT", "RAW_MODE_REQUIRED", "PRESERVE_ONLY_VIOLATION", "INVALID_INPUT"
failure.detailsanyno
failure.messagestringyes
resolutionobjectno
resolution.rangeTextMutationRangenoTextMutationRange
resolution.range.fromintegerno
resolution.range.tointegerno
resolution.selectionTargetSelectionTargetnoSelectionTarget
resolution.selectionTarget.endSelectionPointnoSelectionPoint
resolution.selectionTarget.kind"selection"noConstant: "selection"
resolution.selectionTarget.startSelectionPointnoSelectionPoint
resolution.targetTextAddress \BlockNodeAddressnoOne of: TextAddress, BlockNodeAddress
successfalseyesConstant: false

Example response

{
  "evaluatedRevision": {
    "after": "rev-002",
    "before": "rev-001"
  },
  "resolution": {
    "range": {
      "from": 42,
      "to": 42
    },
    "target": {
      "kind": "block",
      "nodeId": "node-def456",
      "nodeType": "paragraph"
    }
  },
  "success": true
}

Pre-apply throws

  • TARGET_NOT_FOUND
  • CAPABILITY_UNAVAILABLE
  • INVALID_TARGET
  • INVALID_INPUT
  • ADDRESS_STALE
  • DUPLICATE_ID
  • RAW_MODE_REQUIRED
  • PRESERVE_ONLY_VIOLATION
  • CAPABILITY_UNSUPPORTED

Non-applied failure codes

  • INVALID_TARGET
  • NO_OP
  • CAPABILITY_UNAVAILABLE
  • UNSUPPORTED_ENVIRONMENT
  • INVALID_NESTING
  • INVALID_PLACEMENT
  • INVALID_PAYLOAD
  • CAPABILITY_UNSUPPORTED
  • ADDRESS_STALE
  • DUPLICATE_ID
  • INVALID_CONTEXT
  • RAW_MODE_REQUIRED
  • PRESERVE_ONLY_VIOLATION
  • INVALID_INPUT

Raw schemas

{
  "oneOf": [
    {
      "additionalProperties": false,
      "properties": {
        "target": {
          "$ref": "#/$defs/TextAddress"
        },
        "type": {
          "enum": [
            "text",
            "markdown",
            "html"
          ],
          "type": "string"
        },
        "value": {
          "type": "string"
        }
      },
      "required": [
        "value"
      ],
      "type": "object"
    },
    {
      "additionalProperties": false,
      "properties": {
        "content": {
          "oneOf": [
            {
              "type": "object"
            },
            {
              "items": {
                "type": "object"
              },
              "type": "array"
            }
          ]
        },
        "nestingPolicy": {
          "additionalProperties": false,
          "properties": {
            "tables": {
              "enum": [
                "forbid",
                "allow"
              ]
            }
          },
          "type": "object"
        },
        "placement": {
          "enum": [
            "before",
            "after",
            "insideStart",
            "insideEnd"
          ]
        },
        "target": {
          "$ref": "#/$defs/BlockNodeAddress"
        }
      },
      "required": [
        "content"
      ],
      "type": "object"
    }
  ]
}
{
  "oneOf": [
    {
      "additionalProperties": false,
      "properties": {
        "evaluatedRevision": {
          "additionalProperties": false,
          "properties": {
            "after": {
              "type": "string"
            },
            "before": {
              "type": "string"
            }
          },
          "required": [
            "before",
            "after"
          ],
          "type": "object"
        },
        "resolution": {
          "additionalProperties": false,
          "properties": {
            "range": {
              "$ref": "#/$defs/TextMutationRange"
            },
            "selectionTarget": {
              "$ref": "#/$defs/SelectionTarget"
            },
            "target": {
              "oneOf": [
                {
                  "$ref": "#/$defs/TextAddress"
                },
                {
                  "$ref": "#/$defs/BlockNodeAddress"
                }
              ]
            }
          },
          "required": [
            "target",
            "range"
          ],
          "type": "object"
        },
        "success": {
          "const": true
        }
      },
      "required": [
        "success"
      ],
      "type": "object"
    },
    {
      "additionalProperties": false,
      "properties": {
        "evaluatedRevision": {
          "additionalProperties": false,
          "properties": {
            "after": {
              "type": "string"
            },
            "before": {
              "type": "string"
            }
          },
          "required": [
            "before",
            "after"
          ],
          "type": "object"
        },
        "failure": {
          "additionalProperties": false,
          "properties": {
            "code": {
              "enum": [
                "INVALID_TARGET",
                "NO_OP",
                "CAPABILITY_UNAVAILABLE",
                "UNSUPPORTED_ENVIRONMENT",
                "INVALID_NESTING",
                "INVALID_PLACEMENT",
                "INVALID_PAYLOAD",
                "CAPABILITY_UNSUPPORTED",
                "ADDRESS_STALE",
                "DUPLICATE_ID",
                "INVALID_CONTEXT",
                "RAW_MODE_REQUIRED",
                "PRESERVE_ONLY_VIOLATION",
                "INVALID_INPUT"
              ]
            },
            "details": {},
            "message": {
              "type": "string"
            }
          },
          "required": [
            "code",
            "message"
          ],
          "type": "object"
        },
        "resolution": {
          "additionalProperties": false,
          "properties": {
            "range": {
              "$ref": "#/$defs/TextMutationRange"
            },
            "selectionTarget": {
              "$ref": "#/$defs/SelectionTarget"
            },
            "target": {
              "oneOf": [
                {
                  "$ref": "#/$defs/TextAddress"
                },
                {
                  "$ref": "#/$defs/BlockNodeAddress"
                }
              ]
            }
          },
          "required": [
            "target",
            "range"
          ],
          "type": "object"
        },
        "success": {
          "const": false
        }
      },
      "required": [
        "success",
        "failure"
      ],
      "type": "object"
    }
  ]
}
{
  "additionalProperties": false,
  "properties": {
    "evaluatedRevision": {
      "additionalProperties": false,
      "properties": {
        "after": {
          "type": "string"
        },
        "before": {
          "type": "string"
        }
      },
      "required": [
        "before",
        "after"
      ],
      "type": "object"
    },
    "resolution": {
      "additionalProperties": false,
      "properties": {
        "range": {
          "$ref": "#/$defs/TextMutationRange"
        },
        "selectionTarget": {
          "$ref": "#/$defs/SelectionTarget"
        },
        "target": {
          "oneOf": [
            {
              "$ref": "#/$defs/TextAddress"
            },
            {
              "$ref": "#/$defs/BlockNodeAddress"
            }
          ]
        }
      },
      "required": [
        "target",
        "range"
      ],
      "type": "object"
    },
    "success": {
      "const": true
    }
  },
  "required": [
    "success"
  ],
  "type": "object"
}
{
  "additionalProperties": false,
  "properties": {
    "evaluatedRevision": {
      "additionalProperties": false,
      "properties": {
        "after": {
          "type": "string"
        },
        "before": {
          "type": "string"
        }
      },
      "required": [
        "before",
        "after"
      ],
      "type": "object"
    },
    "failure": {
      "additionalProperties": false,
      "properties": {
        "code": {
          "enum": [
            "INVALID_TARGET",
            "NO_OP",
            "CAPABILITY_UNAVAILABLE",
            "UNSUPPORTED_ENVIRONMENT",
            "INVALID_NESTING",
            "INVALID_PLACEMENT",
            "INVALID_PAYLOAD",
            "CAPABILITY_UNSUPPORTED",
            "ADDRESS_STALE",
            "DUPLICATE_ID",
            "INVALID_CONTEXT",
            "RAW_MODE_REQUIRED",
            "PRESERVE_ONLY_VIOLATION",
            "INVALID_INPUT"
          ]
        },
        "details": {},
        "message": {
          "type": "string"
        }
      },
      "required": [
        "code",
        "message"
      ],
      "type": "object"
    },
    "resolution": {
      "additionalProperties": false,
      "properties": {
        "range": {
          "$ref": "#/$defs/TextMutationRange"
        },
        "selectionTarget": {
          "$ref": "#/$defs/SelectionTarget"
        },
        "target": {
          "oneOf": [
            {
              "$ref": "#/$defs/TextAddress"
            },
            {
              "$ref": "#/$defs/BlockNodeAddress"
            }
          ]
        }
      },
      "required": [
        "target",
        "range"
      ],
      "type": "object"
    },
    "success": {
      "const": false
    }
  },
  "required": [
    "success",
    "failure"
  ],
  "type": "object"
}