0

I'm using the code example on notion doc, but it raise the 400 error how to fix it?

below are the code I'm using:

import requests

toggle_heading = 'https://api.notion.com/v1/blocks/{my_blockid}/children'

headers = {

     'Authorization': 'Bearer {my_token}',
     "accept": "application/json",
     "Notion-Version": "2022-06-28",
     "content-type": "application/json"
 }

r = requests.patch(toggle_heading, headers = headers)

print(r.status_code)

 ------------

 raise 400

the code was copy from:

https://developers.notion.com/reference/patch-block-children

1 Answers1

0

There are two problems with your code:

toggle_heading = 'https://api.notion.com/v1/blocks/{my_blockid}/children'

{my_blockid} here is as a string, not as a variable. You need something like:

my_blockid = "fjhdosfjdksljf"
toggle_heading = f'https://api.notion.com/v1/blocks/{my_blockid}/children'

Note the fstring.

For:

headers = {

     'Authorization': 'Bearer {my_token}',
     "accept": "application/json",
     "Notion-Version": "2022-06-28",
     "content-type": "application/json"
 }

Same for this part. {my_token} is a literal string, you need something like:

my_token = "fdklsjflkdsfjl"
headers = {

     'Authorization': f'Bearer {my_token}',
     "accept": "application/json",
     "Notion-Version": "2022-06-28",
     "content-type": "application/json"
 }
Itération 122442
  • 2,644
  • 2
  • 27
  • 73
  • thanks for your response sir, but I have a new question how can I code the request body when I need to append a block children, there have no code example on dev doc in python – Copperfield David Jun 25 '23 at 08:33
  • If you have a new question, please create a new question describing your problem @CopperfieldDavid – Itération 122442 Jul 07 '23 at 05:38