I’m having trouble modifying content in my Notion blocks using their API. I followed the documentation but the text content stays the same after sending update requests.
import json
import requests
import os
from dotenv import load_dotenv, find_dotenv
def update_notion_block():
load_dotenv(find_dotenv())
api_token = os.environ.get("NOTION_TOKEN")
target_block = os.environ.get("TARGET_BLOCK")
request_headers = {
"Authorization": f"Bearer {api_token}",
"Notion-Version": "2021-08-16",
"Content-Type": "application/json"
}
updated_content = {
"paragraph": {
"text": [{
"text": {
"content": "updated text here"
}
}]
}
}
api_endpoint = f"https://api.notion.com/v1/blocks/{target_block}"
response = requests.patch(api_endpoint, headers=request_headers, json=updated_content)
print(f"Status: {response.status_code}")
print(json.dumps(response.json(), indent=2))
if __name__ == "__main__":
update_notion_block()
The response shows status 200 but the original text remains unchanged:
{
"paragraph": {
"text": [
{
"type": "text",
"text": {
"content": "original text here",
"link": null
},
"annotations": {
"bold": false,
"italic": false,
"strikethrough": false,
"underline": false,
"code": false,
"color": "default"
}
}
]
}
}
What am I missing in my implementation?