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

Summary

Insert a raw field code at a target location.
  • Operation ID: fields.insert
  • API member path: editor.doc.fields.insert(...)
  • Mutates document: yes
  • Idempotency: non-idempotent
  • Supports tracked mode: no
  • Supports dry run: no
  • Deterministic target resolution: yes

Expected result

Returns a FieldMutationResult indicating success with the field address or a failure.

Input fields

FieldTypeRequiredDescription
atTextTargetyesTextTarget
at.kind"text"yesConstant: "text"
at.segmentsTextSegment[]yes
instructionstringyes
mode"raw"yesConstant: "raw"

Example request

{
  "at": {
    "kind": "text",
    "segments": [
      {
        "blockId": "block-abc123",
        "range": {
          "end": 10,
          "start": 0
        }
      }
    ]
  },
  "instruction": "example",
  "mode": "raw"
}

Output fields

Variant 1 (field.kind=“field”)

FieldTypeRequiredDescription
fieldobject(kind=“field”)yes
field.blockIdstringyes
field.kind"field"yesConstant: "field"
field.nestingDepthintegerno
field.occurrenceIndexintegeryes
successtrueyesConstant: true

Variant 2 (success=false)

FieldTypeRequiredDescription
failureobjectyes
failure.codestringyes
failure.detailsanyno
failure.messagestringyes
successfalseyesConstant: false

Example response

{
  "field": {
    "blockId": "block-abc123",
    "kind": "field",
    "nestingDepth": 1,
    "occurrenceIndex": 1
  },
  "success": true
}

Pre-apply throws

  • TARGET_NOT_FOUND
  • INVALID_TARGET
  • INVALID_INPUT
  • CAPABILITY_UNAVAILABLE

Non-applied failure codes

  • None

Raw schemas

{
  "additionalProperties": false,
  "properties": {
    "at": {
      "$ref": "#/$defs/TextTarget"
    },
    "instruction": {
      "type": "string"
    },
    "mode": {
      "const": "raw"
    }
  },
  "required": [
    "mode",
    "at",
    "instruction"
  ],
  "type": "object"
}
{
  "oneOf": [
    {
      "additionalProperties": false,
      "properties": {
        "field": {
          "additionalProperties": false,
          "properties": {
            "blockId": {
              "type": "string"
            },
            "kind": {
              "const": "field"
            },
            "nestingDepth": {
              "type": "integer"
            },
            "occurrenceIndex": {
              "type": "integer"
            }
          },
          "required": [
            "kind",
            "blockId",
            "occurrenceIndex"
          ],
          "type": "object"
        },
        "success": {
          "const": true
        }
      },
      "required": [
        "success",
        "field"
      ],
      "type": "object"
    },
    {
      "additionalProperties": false,
      "properties": {
        "failure": {
          "additionalProperties": false,
          "properties": {
            "code": {
              "type": "string"
            },
            "details": {},
            "message": {
              "type": "string"
            }
          },
          "required": [
            "code",
            "message"
          ],
          "type": "object"
        },
        "success": {
          "const": false
        }
      },
      "required": [
        "success",
        "failure"
      ],
      "type": "object"
    }
  ]
}
{
  "additionalProperties": false,
  "properties": {
    "field": {
      "additionalProperties": false,
      "properties": {
        "blockId": {
          "type": "string"
        },
        "kind": {
          "const": "field"
        },
        "nestingDepth": {
          "type": "integer"
        },
        "occurrenceIndex": {
          "type": "integer"
        }
      },
      "required": [
        "kind",
        "blockId",
        "occurrenceIndex"
      ],
      "type": "object"
    },
    "success": {
      "const": true
    }
  },
  "required": [
    "success",
    "field"
  ],
  "type": "object"
}
{
  "additionalProperties": false,
  "properties": {
    "failure": {
      "additionalProperties": false,
      "properties": {
        "code": {
          "type": "string"
        },
        "details": {},
        "message": {
          "type": "string"
        }
      },
      "required": [
        "code",
        "message"
      ],
      "type": "object"
    },
    "success": {
      "const": false
    }
  },
  "required": [
    "success",
    "failure"
  ],
  "type": "object"
}