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

Summary

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

Expected result

Returns a CrossRefMutationResult indicating success with the cross-reference address or a failure.

Input fields

FieldTypeRequiredDescription
atTextTargetyesTextTarget
at.kind"text"yesConstant: "text"
at.segmentsTextSegment[]yes
displayenumyes"content", "pageNumber", "noteNumber", "labelAndNumber", "aboveBelow", "numberOnly", "numberFullContext", "styledContent", "styledPageNumber"
targetobject(kind=“bookmark”) \object(kind=“heading”) \object(kind=“note”) \object(kind=“caption”) \object(kind=“numberedItem”) \object(kind=“styledParagraph”)yesOne of: object(kind=“bookmark”), object(kind=“heading”), object(kind=“note”), object(kind=“caption”), object(kind=“numberedItem”), object(kind=“styledParagraph”)

Example request

{
  "at": {
    "kind": "text",
    "segments": [
      {
        "blockId": "block-abc123",
        "range": {
          "end": 10,
          "start": 0
        }
      }
    ]
  },
  "display": "content",
  "target": {
    "kind": "bookmark",
    "name": "example"
  }
}

Output fields

Variant 1 (crossRef.kind=“inline”)

FieldTypeRequiredDescription
crossRefobject(kind=“inline”)yes
crossRef.anchorInlineAnchoryesInlineAnchor
crossRef.anchor.endPositionyesPosition
crossRef.anchor.end.blockIdstringyes
crossRef.anchor.end.offsetintegeryes
crossRef.anchor.startPositionyesPosition
crossRef.anchor.start.blockIdstringyes
crossRef.anchor.start.offsetintegeryes
crossRef.kind"inline"yesConstant: "inline"
crossRef.nodeType"crossRef"yesConstant: "crossRef"
successtrueyesConstant: true

Variant 2 (success=false)

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

Example response

{
  "crossRef": {
    "anchor": {
      "end": {
        "blockId": "block-abc123",
        "offset": 0
      },
      "start": {
        "blockId": "block-abc123",
        "offset": 0
      }
    },
    "kind": "inline",
    "nodeType": "crossRef"
  },
  "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"
    },
    "display": {
      "enum": [
        "content",
        "pageNumber",
        "noteNumber",
        "labelAndNumber",
        "aboveBelow",
        "numberOnly",
        "numberFullContext",
        "styledContent",
        "styledPageNumber"
      ]
    },
    "target": {
      "oneOf": [
        {
          "additionalProperties": false,
          "properties": {
            "kind": {
              "const": "bookmark"
            },
            "name": {
              "type": "string"
            }
          },
          "required": [
            "kind",
            "name"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "properties": {
            "kind": {
              "const": "heading"
            },
            "nodeId": {
              "type": "string"
            }
          },
          "required": [
            "kind",
            "nodeId"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "properties": {
            "kind": {
              "const": "note"
            },
            "noteId": {
              "type": "string"
            }
          },
          "required": [
            "kind",
            "noteId"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "properties": {
            "kind": {
              "const": "caption"
            },
            "nodeId": {
              "type": "string"
            }
          },
          "required": [
            "kind",
            "nodeId"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "properties": {
            "kind": {
              "const": "numberedItem"
            },
            "nodeId": {
              "type": "string"
            }
          },
          "required": [
            "kind",
            "nodeId"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "properties": {
            "direction": {
              "enum": [
                "before",
                "after"
              ]
            },
            "kind": {
              "const": "styledParagraph"
            },
            "styleName": {
              "type": "string"
            }
          },
          "required": [
            "kind",
            "styleName"
          ],
          "type": "object"
        }
      ]
    }
  },
  "required": [
    "at",
    "target",
    "display"
  ],
  "type": "object"
}
{
  "oneOf": [
    {
      "additionalProperties": false,
      "properties": {
        "crossRef": {
          "additionalProperties": false,
          "properties": {
            "anchor": {
              "$ref": "#/$defs/InlineAnchor"
            },
            "kind": {
              "const": "inline"
            },
            "nodeType": {
              "const": "crossRef"
            }
          },
          "required": [
            "kind",
            "nodeType",
            "anchor"
          ],
          "type": "object"
        },
        "success": {
          "const": true
        }
      },
      "required": [
        "success",
        "crossRef"
      ],
      "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": {
    "crossRef": {
      "additionalProperties": false,
      "properties": {
        "anchor": {
          "$ref": "#/$defs/InlineAnchor"
        },
        "kind": {
          "const": "inline"
        },
        "nodeType": {
          "const": "crossRef"
        }
      },
      "required": [
        "kind",
        "nodeType",
        "anchor"
      ],
      "type": "object"
    },
    "success": {
      "const": true
    }
  },
  "required": [
    "success",
    "crossRef"
  ],
  "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"
}