# create.tableOfContents

> Insert a new table of contents at the target position.



- Member path: `doc.create.tableOfContents(…)`
- Mutates document: yes
- Idempotency: `non-idempotent`
- Supports tracked mode: no
- Supports dry run: yes

## Expected result

Returns a CreateTableOfContentsResult with the new TOC block address.

## Input schema

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$defs": {
    "BlockNodeAddress": {
      "type": "object",
      "properties": {
        "kind": {
          "const": "block"
        },
        "nodeType": {
          "enum": [
            "paragraph",
            "heading",
            "listItem",
            "table",
            "tableRow",
            "tableCell",
            "tableOfContents",
            "image",
            "sdt"
          ]
        },
        "nodeId": {
          "type": "string"
        },
        "story": {
          "$ref": "#/$defs/StoryLocator"
        }
      },
      "additionalProperties": false,
      "required": [
        "kind",
        "nodeType",
        "nodeId"
      ]
    },
    "StoryLocator": {
      "description": "Story scope. Defaults to document body when omitted. Use {kind:'story', storyType:'body'} for body, or other storyType values for headers, footers, footnotes, endnotes.",
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "body"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "headerFooterSlot"
            },
            "section": {
              "$ref": "#/$defs/SectionAddress"
            },
            "headerFooterKind": {
              "enum": [
                "header",
                "footer"
              ]
            },
            "variant": {
              "enum": [
                "default",
                "first",
                "even"
              ]
            },
            "resolution": {
              "enum": [
                "effective",
                "explicit"
              ]
            },
            "onWrite": {
              "enum": [
                "materializeIfInherited",
                "editResolvedPart",
                "error"
              ]
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType",
            "section",
            "headerFooterKind",
            "variant"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "headerFooterPart"
            },
            "refId": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType",
            "refId"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "footnote"
            },
            "noteId": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType",
            "noteId"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "endnote"
            },
            "noteId": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType",
            "noteId"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "textbox"
            },
            "textboxId": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType",
            "textboxId"
          ]
        }
      ]
    },
    "SectionAddress": {
      "type": "object",
      "properties": {
        "kind": {
          "const": "section"
        },
        "sectionId": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "required": [
        "kind",
        "sectionId"
      ]
    }
  },
  "type": "object",
  "properties": {
    "at": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "documentStart"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "documentEnd"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "before"
            },
            "target": {
              "$ref": "#/$defs/BlockNodeAddress"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "target"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "after"
            },
            "target": {
              "$ref": "#/$defs/BlockNodeAddress"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "target"
          ]
        }
      ]
    },
    "config": {
      "type": "object",
      "properties": {
        "outlineLevels": {
          "type": "object",
          "properties": {
            "from": {
              "type": "integer"
            },
            "to": {
              "type": "integer"
            }
          },
          "additionalProperties": false,
          "required": [
            "from",
            "to"
          ]
        },
        "useAppliedOutlineLevel": {
          "type": "boolean"
        },
        "tcFieldIdentifier": {
          "type": "string"
        },
        "tcFieldLevels": {
          "type": "object",
          "properties": {
            "from": {
              "type": "integer"
            },
            "to": {
              "type": "integer"
            }
          },
          "additionalProperties": false,
          "required": [
            "from",
            "to"
          ]
        },
        "hyperlinks": {
          "type": "boolean"
        },
        "hideInWebView": {
          "type": "boolean"
        },
        "omitPageNumberLevels": {
          "type": "object",
          "properties": {
            "from": {
              "type": "integer"
            },
            "to": {
              "type": "integer"
            }
          },
          "additionalProperties": false,
          "required": [
            "from",
            "to"
          ]
        },
        "separator": {
          "type": "string"
        },
        "includePageNumbers": {
          "type": "boolean"
        },
        "tabLeader": {
          "enum": [
            "none",
            "dot",
            "hyphen",
            "underscore",
            "middleDot"
          ]
        },
        "rightAlignPageNumbers": {
          "type": "boolean"
        }
      },
      "additionalProperties": false
    },
    "instruction": {
      "type": "string"
    }
  },
  "additionalProperties": false
}
```

## Output schema

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$defs": {},
  "oneOf": [
    {
      "type": "object",
      "properties": {
        "success": {
          "const": true
        },
        "toc": {
          "type": "object",
          "properties": {
            "kind": {
              "const": "block"
            },
            "nodeType": {
              "const": "tableOfContents"
            },
            "nodeId": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "nodeType",
            "nodeId"
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "success",
        "toc"
      ]
    },
    {
      "type": "object",
      "properties": {
        "success": {
          "const": false
        },
        "failure": {
          "type": "object",
          "properties": {
            "code": {
              "enum": [
                "NO_OP",
                "INVALID_TARGET",
                "TARGET_NOT_FOUND",
                "CAPABILITY_UNAVAILABLE",
                "INVALID_INSERTION_CONTEXT",
                "PAGE_NUMBERS_NOT_MATERIALIZED"
              ]
            },
            "message": {
              "type": "string"
            },
            "details": {}
          },
          "additionalProperties": false,
          "required": [
            "code",
            "message"
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "success",
        "failure"
      ]
    }
  ]
}
```

## Pre-apply throws

- `INVALID_TARGET`
- `TARGET_NOT_FOUND`
- `INVALID_INPUT`
- `CAPABILITY_UNAVAILABLE`

## Non-applied receipt codes

- `NO_OP`
- `INVALID_INSERTION_CONTEXT`

