Write content
How to write Markdown content into a DingTalk Docs document?
-
Option 1: Insert content (append without affecting existing content)
Call the Insert content API to insert Markdown content at a specified location in the document:
-
Option 2: Overwrite the document (clear and rewrite)
Call the Overwrite document (App authorization) API to overwrite the entire document content in Markdown format:
Overwriting clears all existing content in the document. This is a destructive action, so use it with caution. To append content only, use the Insert content API instead.
Block element operations
How to insert a paragraph with content
Call the Insert block element API to insert a paragraph block into the document, and use thechildren field to specify the inline elements within the paragraph:
paragraph object cannot be omitted. Even if the paragraph has no special attributes, pass an empty object {}.
How to insert a block element at a specific location (not at the end)
When calling the Insert block element API, specify the target location withblockId or index, and use the where parameter to control whether to insert before or after the target:
| Parameter | Description |
|---|---|
blockId | The unique identifier of the target block. The new block is inserted before or after this block. |
index | When blockId is not provided, the index-th top-level block in the document is used as the target location (starting from 0). |
where | "before" inserts before the target location; "after" inserts after it (default: "after"). |
How to insert a heading
Call the Insert block element API. SetblockType to heading and use level in the heading object to specify the heading level (1–6):
heading.level and heading levels:
| level | Heading |
|---|---|
1 | Heading 1 (H1) |
2 | Heading 2 (H2) |
3 | Heading 3 (H3) |
4 | Heading 4 (H4) |
5 | Heading 5 (H5) |
6 | Heading 6 (H6) |
How to insert a Quote block
Call the Insert block element API. SetblockType to blockquote and pass the quote content in the blockquote object:
How to insert a Highlight block with a nested paragraph
Thechildren of a Highlight block must be an array of BlockElement. When calling the Insert block element API, pass the child paragraph in children:
children types. The children of a paragraph block can only be inline elements, while the children of a Highlight block can only be block elements.
How to insert columns
Call the Insert block element API. SetblockType to columns, use columns.size to specify the number of columns, and pass the block element content for each column in children:
columns object:
| Field | Type | Description |
|---|---|---|
size | Number | Number of columns. |
noFill | Boolean | Whether to automatically fill the background color. Default: false. |
children of columns must be a BlockElement array, not inline elements.
How to insert a Numbered List
Call the Insert block element API. SetblockType to orderedList, pass the list attributes in the orderedList object, and pass the list item text in children:
list object:
| Field | Type | Description |
|---|---|---|
listId | String | The unique identifier of the list. Multiple list items in the same list should share the same listId. |
level | Number | List indent tier, starting from 0. |
listStyleType | String | List style type. Use "decimal" for a Numbered List. |
How to insert a Bulleted List
Call the Insert block element API. SetblockType to unorderedList, pass the list attributes in the unorderedList object, and pass the list item text in children:
listId of a Numbered List or Bulleted List associates multiple list items with the same list. To insert multiple items belonging to the same list, use the same listId for each item. You can insert all items in one call using the BatchOperate API.
Query operations
How to get the blockId of all block elements in a document?
Call the Query block element API to retrieve the list of top-level block elements under the document’s root node. Each element includes itsid (the blockId):