I’m working with the Notion API and running into a strange issue. I can successfully create pages using my integration, but when I try to add entries to a database on the same page, I get a 404 error saying the database isn’t found or shared with my integration.
Here’s my function for building new pages:
def build_notion_document(token, template_page_id, db_id):
endpoint = "https://api.notion.com/v1/pages"
request_headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json",
"Notion-Version": "2022-06-28"
}
payload = {
"parent": {
"type": "page_id",
"page_id": template_page_id
},
"properties": {
"title": [{
"text": {
"content": "Study Cards Configuration"
}
}]
},
"children": [{
"object": "block",
"type": "paragraph",
"paragraph": {
"rich_text": [{
"type": "text",
"text": {
"content": "Keep these IDs secure to protect your study cards setup."
}
}]
}
}]
}
result = requests.post(endpoint, headers=request_headers, json=payload)
return result.status_code == 200
This works perfectly. But when I try to insert data into the database with this function:
def insert_database_entry(token, db_id, entry_properties):
api_url = f"https://api.notion.com/v1/pages/"
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json",
"Notion-Version": "2022-06-28"
}
request_data = {
"parent": {
"type": "database_id",
"database_id": db_id
},
"properties": entry_properties
}
response = requests.post(api_url, headers=headers, json=request_data)
if response.status_code in [200, 201]:
print("Entry created successfully!")
return response.json()
else:
print(f"Failed to create entry: {response.text}")
return response.json()
I get this error: {"object":"error","status":404,"code":"object_not_found","message":"Could not find database with ID: 583adfba-e506-43a8-b059-47f9c2d63a06. Make sure the relevant pages and databases are shared with your integration.","request_id":"4269100f-74d3-4b2a-8701-17b49ec9d43c"}
Since I can create the page successfully, shouldn’t the database on that same page be accessible to my integration as well? What am I missing here?