0

I want to be able to update a Notion block in a way that it adds a piece of text when it finds a bolded word. I want it in this way:

This text is important for some reason.

The text before running the code.

This text is important(1) for some reason.

The text after running the code.

I see that Notion fragments the contents of a block into pieces with different styles, so the previous line can be accessed, after retrieving and a JSON formatting, through ["paragraph"]["rich_text"][0], [1] and [2].

What I tried is to add that "(1)" through insert, but everytime I try to send it to Notion it throws the same error:

ValueError: too many values to unpack (expected 2)

I dumped the old and the new data into a json file and it looks nicely inserted. I don't know where the error can be. I'm quite new into programming so it's hard to see where the error is leading me to. This is the code I'm using for the insertion:

data = retrieveBlock()

newData = {
  'type': 'text', 
  'text': { 
    'content': '(1)', 
    'link': None
  }, 
  'annotations': {
    'bold': False, 
    'italic': False, 
    'strikethrough': False, 
    'underline': False, 
    'code': False, 
    'color': 'default'
  }, 
  'plain_text': '(1)', 
  'href': None
}

data.insert(2, newData)

res = requests.request("PATCH", 
                        block_url + block_id, 
                        data=data, 
                        headers=headers)

Thanks for the help!

I tried loading and dumping JSON before and after calling the old and the new data. I also tried reformatting the keys on the new data, but it looks like they are later ordered automatically.

Sanval
  • 1

0 Answers0