My python file:
import requests
from app import config
from app import itemSorter
from datetime import datetime
def getToDoItem(content):
return{"type": "to_do","to_do": {"rich_text": [{"type": "text","text": {"content": content,}}],"color": "default",}}
def appendToDo(id, item_input_list):
url = f"{config.notion_url}blocks/{id}/children"
headers = {
"Authorization": "Bearer " + config.notion_api_key,
"Accept": "application/json",
"Notion-Version": "2022-02-22",
"Content-Type": "application/json"
}
new_page_childs = []
new_page_childs.append(getToDoItem(str(datetime.now())))
for child in item_input_list:
new_page_childs.append(getToDoItem(child))
payload ={"children":new_page_childs}
response = requests.patch(url,json=payload, headers=headers)
def populateNotion():
appendToDo(config.notion_shoppinglist, itemSorter.getSortedShoppingList())
This used to work perfectly until last week. All the other parts of the system that interact with Notion still work. I'm able to read and write from other databases and pages with the same API Key and notion URL (v1).
I don't get any errors, but the items are just not added to the page.
Already tried:
ensured that the integration is still connected to my notion
refreshed the API key
For some reason, I can not invite the integration to the page as done here at 6:32. But I can not with other pages eighter.
Never mind.
For some reason I did not print the error in the right way initially.
With print(response.json())
is saw this:
{'object': 'error', 'status': 400, 'code': 'validation_error', 'message': 'body failed validation: body.children.length should be ≤ `100`, instead was `107`.'}
So I guess splitting up the writing into two parts will to the job.
def populateNotion():
items=itemSorter.getSortedShoppingList()
chunks = [items[i:i+80] for i in range(0, len(items), 80)]
for chunk in chunks:
appendToDo(config.notion_shoppinglist, chunk)