I’m having trouble with my Python script that adds to-do items to a Notion page. It was working fine until recently but now it’s not adding anything. Here’s my code:
import requests
from settings import api_config
from item_manager import task_organizer
from datetime import datetime
def create_task(description):
return {
"type": "to_do",
"to_do": {
"rich_text": [{"type": "text", "text": {"content": description}}],
"color": "default"
}
}
def add_tasks(page_id, task_list):
endpoint = f"{api_config.base_url}blocks/{page_id}/children"
headers = {
"Authorization": f"Bearer {api_config.secret_key}",
"Accept": "application/json",
"Notion-Version": "2022-02-22",
"Content-Type": "application/json"
}
new_tasks = [create_task(str(datetime.now()))]
new_tasks.extend([create_task(task) for task in task_list])
payload = {"children": new_tasks}
response = requests.patch(endpoint, json=payload, headers=headers)
def update_notion_list():
add_tasks(api_config.list_id, task_organizer.get_organized_tasks())
The script runs without errors but doesn’t add tasks to the page. I’ve checked the API key and URL, and other parts of my system can still interact with Notion. Any ideas what might be wrong?
yo, had similar probs. check ur api perms, maybe notion revoked access. also, try printin the response.json() to see if there’s any error msgs. sometimes notion’s weird bout rate limits too, so maybe add a lil delay between requests. good luck mate!
Hey there, I’ve been using the Notion API for a while now and I’ve run into similar issues. One thing that’s not immediately obvious from your code is whether you’re handling the API response correctly. Even if the request goes through without throwing an exception, Notion might be returning an error in the response body.
I’d suggest modifying your add_tasks function to check the response status code and content. Something like this:
response = requests.patch(endpoint, json=payload, headers=headers)
if response.status_code != 200:
print(f'Error: {response.status_code}, {response.text}')
return False
return True
This way, you’ll be able to see if Notion is actually reporting any errors. Also, make sure your integration has the correct capabilities enabled in the Notion workspace settings. Sometimes, permissions can get reset without you realizing it.
Lastly, have you tried creating a new integration and using its API key? Sometimes that can resolve mysterious issues. Hope this helps!
I encountered a similar issue with my Notion API script recently. Have you double-checked that your page_id and list_id are still valid? Sometimes Notion regenerates these IDs, which can break existing integrations.
Another potential cause could be changes in the Notion API version. Try updating your ‘Notion-Version’ header to the latest version (currently ‘2022-06-28’).
If those don’t work, I’d suggest adding some logging or print statements to see exactly where the process is failing. Pay special attention to the response from the API call - it might contain useful error information.
Lastly, ensure your task_organizer.get_organized_tasks() is actually returning data. If it’s returning an empty list, that could explain why no tasks are being added.