Hi
After several hours of trial and error I have this working, but the technique is somewhat different that suggested (but that suggestion set me on the right path so Thanks!)
Here is the scenario
And there is what it created on a blank database page
My goal was to be able to create and add to children of toggle blocks in particular, but this will work on any block that can have nested content (or really any block children). It works well for testing purposes. I will clean it up for my intended use, but is proof of concept now.
A few Notes:
- Just doing API Append Block Children doesn’t actually create children. It creates equal level blocks.
- The After parameter lets one determine which block gets added to below (but still not as a child)
- The way to create nested blocks is to make children of children in the body commands of the API Append Block Children action.
- Once true child blocks are created by this 1st API action, one can then do an API Get action to Retrieve Block Children and then a 2nd Append Block Children action to add to or overwrite those previously created nested blocks by using the new true child block IDs from the Retrieve Block Children action.
Likely this wont be fully clear to anyone not trying to do this. In my case, I like to have Notes with sections inside toggle blocks and have reason to do this via automations vs templates.
Below id the Blueprint file for anyone this mmight be helpful to…
2023-11-20 Nested Toggle Blocks blueprint.json (97.2 KB)
Thanks!!
PS Here is the test of the Body command sent via the API Append Block Children action. This is what creates the parent toggle blocks and the nested children. I also then use it a second time after the Retrieve Child Blocks, thus creating multiple 4-level deep heirarchy structures [again for proof of concept]…
{
"children": [
{
"object": "block",
"type": "toggle",
"toggle": {
"rich_text": [
{
"type": "text",
"text": {
"content": "1St New Toggle Block"
}
}
],
"children": [
{
"object": "block",
"type": "paragraph",
"paragraph": {
"rich_text": [
{
"type": "text",
"text": {
"content": "1St Par inside 1st Toggle Block"
}
}
]
}
},
{
"object": "block",
"type": "paragraph",
"paragraph": {
"rich_text": [
{
"type": "text",
"text": {
"content": "2nd Par inside 1st Toggle Block"
}
}
]
}
}
]
}
},
{
"object": "block",
"type": "toggle",
"toggle": {
"rich_text": [
{
"type": "text",
"text": {
"content": "2nd New Toggle Block"
}
}
],
"children": [
{
"object": "block",
"type": "paragraph",
"paragraph": {
"rich_text": [
{
"type": "text",
"text": {
"content": "1St Par inside 2nd Toggle Block"
}
}
]
}
},
{
"object": "block",
"type": "paragraph",
"paragraph": {
"rich_text": [
{
"type": "text",
"text": {
"content": "2nd Par inside 2nd Toggle Block"
}
}
]
}
}
]
}
}
]
}
And here is where that code goes in the 2 Append Block Children API modules…