Skip to main content

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 the children field to specify the inline elements within the paragraph:
If the call succeeded, the response is in the following format:
The 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 with blockId or index, and use the where parameter to control whether to insert before or after the target:

How to insert a heading

Call the Insert block element API. Set blockType to heading and use level in the heading object to specify the heading level (1–6):
If the call succeeded, the response is in the following format:
Mapping between heading.level and heading levels:

How to insert a Quote block

Call the Insert block element API. Set blockType to blockquote and pass the quote content in the blockquote object:
If the call succeeded, the response is in the following format:

How to insert a Highlight block with a nested paragraph

The children of a Highlight block must be an array of BlockElement. When calling the Insert block element API, pass the child paragraph in children:
Different block element types accept different 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. Set blockType to columns, use columns.size to specify the number of columns, and pass the block element content for each column in children:
If the call succeeded, the response is in the following format:
Fields of the columns object: The children of columns must be a BlockElement array, not inline elements.

How to insert a Numbered List

Call the Insert block element API. Set blockType to orderedList, pass the list attributes in the orderedList object, and pass the list item text in children:
If the call succeeded, the response is in the following format:
Common fields of the list object:

How to insert a Bulleted List

Call the Insert block element API. Set blockType to unorderedList, pass the list attributes in the unorderedList object, and pass the list item text in children:
If the call succeeded, the response is in the following format:
The 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 its id (the blockId):
If the call succeeded, the response is in the following format:
The Query block element API currently only supports querying top-level block elements under the document’s root node. Recursive queries on child blocks nested inside containers such as Highlight blocks are not supported.