Notion: How to Append Block Child?

HI New user and non-coder :frowning:

In Notion I am trying to append content as the child of a block in the body of a database item page. I do not see a Notion module to append to a specific block, only to append a database item (a page). While I am able to obtain the desired block ID, etc, I see no way to append new text as a child to a specific block. Can this be done? If so how?

Alternatively, I could try a Notion “Make API Call” module. My problem here is as a non-coder I don’t know what to enter.

Any help would be appreciated. See Scenario below…

I am do know the Block ID from the prior Notion module. But what do I enter in the highlighted area to target that ID and add new text as a child block?

Thanks!!

Hi, in the “method” option, you can select “patch” instead of “post” (as per the instructions of the notion API documentation). In the “body” section of the module, you can use something similar to this (edit the content based on what you actually would like to insert). The key is to use the “after” parameter to specify below which block you want to insert the content on the page:

{
“children”: [
{
“object”: “block”,
“type”: “heading_2”,
“heading_2”: {
“rich_text”: [{ “type”: “text”, “text”: { “content”: “Lacinato kale” } }]
}
}],
“after”: “{{blockId}}”}

2 Likes

Hi @Simo
Thanks for helping me. I did what you instructed but its still not working. Likely I have some minor json formatting problem.

Here is what I entered (note I also updated to latest Notion API version)

and here is the error I continue to receive…

I manually pasted the block ID for the block i am trying to add child text to. T receive that from the prior API module, which gets block info for the target page as shown below

Are you able to see what I am doing wrong and help me fix my body input?

Thank you very much!

@Simo adding to the above reply…

In looking at my screenshots above, I see a problem: Because each time I run the scenario, it created a new db item, the target block ID changes. However, If I just use the mapped dynamic “ID” field from the prior module in Make, it is not specific to the single block I am trying to add the child content to. Do you know how I can use the mapped block “ID” field but also specify which specific block? Could I somehow filter on the Text of the desired block or something like that? How?

I tried to filter on the target block’s text content and then use the mapped “ID” field (which was a direct paste of your suggested body contents)…still not working???

Make is easy and hard!!

For the first issue you mentioned (body validation error), try to remove the “application/json” header from the “Make an API call” module. I find that this often fixes that error.

For your second point, yes filtering based on the text content sounds like a good approach if you know the content is always the same. To do this successfully, you may need to add an Iterator module after the module that retrieves the blocks ID

2 Likes

@Simo Thanks for trying to help again

Some progress but still error on last module…

Here is the updated scenario

  • The Iterator does break the existing 3 existing blocks into 3 separate bundles
  • My filter on the text content of the existing blocks, does work to only pass the single bundle of the desired target block and I can confirm the correct block ID is passed to the final Module (the Append Block Children module).

All good so far…BUT…

I tried manually removing the auto created header as you mentioned but it did not male a difference… the final module still fails on 400 json error but the contents are a little different…

HANDLED ERROR

  • type
    RuntimeError
  • message
    [400] body failed validation: body.children should be defined, instead was undefined.

Here is the blueprint file…
2023.11.18 Notion Body Toggles Forum Post ANSWER NOT WORKING blueprint.json (136.5 KB)

Might there be an error if the Body script you posted? If not, what do you think is the issue?

Thanks again for your help!

1 Like

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…

5 Likes

Hey there @ccclapp :wave:

Congratulations on solving this problem with a bit of assistance from @Simo. :clap: You truly did a great job.

We appreciate you coming back and sharing your progress and solution with us here. This way our community stays tidy and clean for other users to look for solutions.

Keep up the awesome work! :sunny:

1 Like