Database not found error when adding entries via Notion API integration

I’m working with the Notion API and running into a weird issue. I can successfully create new pages using my integration, but when I try to add entries to a database, I get a 404 error stating that the database can’t be found.

Here’s my function for adding database entries:

def insert_database_entry(token, db_id, entry_data):
    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": "database_id",
            "database_id": db_id
        },
        "properties": entry_data
    }
    
    result = requests.post(endpoint, headers=request_headers, json=payload)
    
    if result.status_code in [200, 201]:
        print("Entry added successfully!")
        return result.json()
    else:
        print(f"Failed to add entry: {result.text}")
        return result.json()

The error message indicates it can’t locate the database and suggests sharing it with the integration. However, this is confusing because I can create pages without any issues using the same integration credentials. What might I be missing?

ya, def sounds like a permissions thing. even if ur integration works for pages, the dbs need to be shared explicitly. check the sharing settings for the db and add ur integration. this is what helped me too!

This exact issue got me when I first started with the Notion API. Here’s the thing - databases need explicit permission sharing, even if your integration already has workspace access. Go to your database in Notion, hit the three dots in the top right, click “Add connections” and add your integration by name. Just because you can create pages elsewhere doesn’t mean you can access individual databases. I spent hours debugging this thinking it was my code. The 404 error’s misleading too - it makes you think the database doesn’t exist when it’s really just a permissions thing. Share the database with your integration and your code should work fine.

Had the same frustrating issue last month. Notion handles database permissions differently than regular pages. When you share a database with your integration, you’re giving it access to both read the structure AND create new entries. Your code looks fine - this is definitely a Notion permissions problem. Go to your database, hit the share button, and invite your integration directly. You’ll see it listed in the database connections when it’s working. After that, your code should work right away without any changes.

Yeah, permissions are definitely the issue. But instead of fighting with API permissions and manual database sharing every time, I just automate everything through Latenode.

It handles all the database connection stuff automatically so I can focus on the actual workflow instead of debugging 404s all day.

You connect your Notion account once and Latenode manages the permissions. You can also set up triggers for form submissions or webhooks without touching Python.

I wasted hours on these API headaches before switching to automation platforms. Now my Notion stuff actually works and I build workflows in minutes, not days.

Check it out if you’re doing regular Notion automation: https://latenode.com