How to retrieve and create the Toggle Heading blocks?

1k Views Asked by At

I want to create the toggle headings 1-3 via the Notion API. However, I cannot find the distinction between normal headers and toggle headers in the API.

https://developers.notion.com/reference/block#heading-one-blocks — this doc only lists "type": "heading_1" without any additional properties to distinguish the toggle header from the normal (non-toggle) header.

When I get the toggle header block via API, I also cannot see any properties that indicate that the header is a toggle heading: Getting a toggle heading 1 block via Notion API - IntelliJ Debugger

Is it overall possible to create the toggle headings via the API? If yes then how?

1

There are 1 best solutions below

0
On BEST ANSWER

It looks like the API itself actually supports creating the headings with the children in it which will make the header a toggle header.

It's just the wrapping JVM library that I am using that does not support setting children to the HeadingOne, HeadingTwo, HeadingThree blocks.

I've added an issue for the library, see https://github.com/seratch/notion-sdk-jvm/issues/45.

Working example via the pure API (replace YOUR_PAGE_ID with your Notion page id) and set the NOTION_API_TOKEN to your Notion token:

curl -X PATCH 'https://api.notion.com/v1/blocks/YOUR_PAGE_ID/children' \
  -H 'Authorization: Bearer '"$NOTION_API_KEY"'' \
  -H "Content-Type: application/json" \
  -H "Notion-Version: 2022-02-22" \
  --data '{
  "children": [
    {
      "object": "block",
      "type": "heading_2",
      "heading_2": {
        "rich_text": [{ "type": "text", "text": { "content": "Heading 2 from script (try 3)" } }],
        "children": [
          {
            "object": "block",
            "type": "paragraph",
            "paragraph": {
              "rich_text": [
                {
                  "type": "text",
                  "text": {
                    "content": "Child in heading 2."
                  }
                }
              ]
            }
          }
        ]
      }
    }
  ]
}'