> ## Documentation Index
> Fetch the complete documentation index at: https://superdoc-caio-pizzol-docs-ai-core-preset.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# crossRefs.insert

> Insert a new cross-reference field at a target location.

## 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: `yes`
* Deterministic target resolution: `yes`

## Expected result

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

## Input fields

| Field         | Type                                                                                                                                                                | Required | Description                                                                                                                                                       |
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `at`          | TextTarget                                                                                                                                                          | yes      | TextTarget                                                                                                                                                        |
| `at.kind`     | `"text"`                                                                                                                                                            | yes      | Constant: `"text"`                                                                                                                                                |
| `at.segments` | TextSegment\[]                                                                                                                                                      | yes      |                                                                                                                                                                   |
| `at.story`    | StoryLocator                                                                                                                                                        | no       | StoryLocator                                                                                                                                                      |
| `display`     | enum                                                                                                                                                                | yes      | `"content"`, `"pageNumber"`, `"noteNumber"`, `"labelAndNumber"`, `"aboveBelow"`, `"numberOnly"`, `"numberFullContext"`, `"styledContent"`, `"styledPageNumber"`   |
| `target`      | object(kind="bookmark") \| object(kind="heading") \| object(kind="note") \| object(kind="caption") \| object(kind="numberedItem") \| object(kind="styledParagraph") | yes      | One of: object(kind="bookmark"), object(kind="heading"), object(kind="note"), object(kind="caption"), object(kind="numberedItem"), object(kind="styledParagraph") |

### Example request

```json theme={null}
{
  "at": {
    "kind": "text",
    "segments": [
      {
        "blockId": "block-abc123",
        "range": {
          "end": 10,
          "start": 0
        }
      }
    ],
    "story": {
      "kind": "story",
      "storyType": "body"
    }
  },
  "display": "content",
  "target": {
    "kind": "bookmark",
    "name": "example"
  }
}
```

## Output fields

### Variant 1 (success=true)

| Field                           | Type                  | Required | Description            |
| ------------------------------- | --------------------- | -------- | ---------------------- |
| `crossRef`                      | object(kind="inline") | yes      |                        |
| `crossRef.anchor`               | InlineAnchor          | yes      | InlineAnchor           |
| `crossRef.anchor.end`           | Position              | yes      | Position               |
| `crossRef.anchor.end.blockId`   | string                | yes      |                        |
| `crossRef.anchor.end.offset`    | integer               | yes      |                        |
| `crossRef.anchor.start`         | Position              | yes      | Position               |
| `crossRef.anchor.start.blockId` | string                | yes      |                        |
| `crossRef.anchor.start.offset`  | integer               | yes      |                        |
| `crossRef.kind`                 | `"inline"`            | yes      | Constant: `"inline"`   |
| `crossRef.nodeType`             | `"crossRef"`          | yes      | Constant: `"crossRef"` |
| `success`                       | `true`                | yes      | Constant: `true`       |

### Variant 2 (success=false)

| Field             | Type    | Required | Description       |
| ----------------- | ------- | -------- | ----------------- |
| `failure`         | object  | yes      |                   |
| `failure.code`    | string  | yes      |                   |
| `failure.details` | any     | no       |                   |
| `failure.message` | string  | yes      |                   |
| `success`         | `false` | yes      | Constant: `false` |

### Example response

```json theme={null}
{
  "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

<Accordion title="Raw input schema">
  ```json theme={null}
  {
    "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"
  }
  ```
</Accordion>

<Accordion title="Raw output schema">
  ```json theme={null}
  {
    "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"
      }
    ]
  }
  ```
</Accordion>

<Accordion title="Raw success schema">
  ```json theme={null}
  {
    "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"
  }
  ```
</Accordion>

<Accordion title="Raw failure schema">
  ```json theme={null}
  {
    "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"
  }
  ```
</Accordion>
