How to update specific rows in Notion database using Python client

I’m working with a Notion database that stores video file information and need help updating specific records. My database has columns for file paths, names, and other details.

I can successfully read data from the database and rename files, but I’m stuck on updating the database rows with new file paths after renaming.

Here’s my current code for reading the database:

notion_client = Client(auth=API_TOKEN)
database_data = notion_client.databases.query(database_id=my_database_id)

for record in database_data['results']:
    video_name = record['properties']['VideoName']['rich_text'][0]['plain_text']
    folder_path = record['properties']['FolderPath']['title'][0]['plain_text']
    rename_video_file(video_name, folder_path)

The file renaming works fine using os.rename(). Now I need to update the database with the new paths, but I can’t figure out the correct syntax.

I tried this approach but it doesn’t work:

def update_database_record(old_name, updated_path):
    notion_client.databases.update({
        "database_id": my_database_id,
        "properties": {
            'FolderPath': {'title': [{'text': {'content': updated_path}}]}
        }
    })

I get an error about missing database ID. I think I need something like “update where VideoName equals old_name” but can’t find examples in the documentation.

Can someone show me the proper way to update specific database rows using the Python notion-client? I’m confused about the difference between updating database structure versus updating individual page properties.

You’re mixing up database updates with page updates. databases.update() changes the database schema itself - not individual records. You need pages.update() to modify specific rows. I made this exact mistake when I started with Notion’s API. Each row in your database is actually a “page” object with its own page ID. Grab the page ID during your initial query, then use it for updates. Here’s the fix: for record in database_data['results']: page_id = record['id']; video_name = record['properties']['VideoName']['rich_text'][0]['plain_text']; folder_path = record['properties']['FolderPath']['title'][0]['plain_text']; new_path = rename_video_file(video_name, folder_path); notion_client.pages.update(page_id=page_id, properties={'FolderPath': {'title': [{'text': {'content': new_path}}]}}). Use pages.update() with a specific page_id instead of trying to update the entire database. Works reliably across different database structures.

yeah, i see what’s wrong. you’re updating the whole database instead of individual pages. each row is a page with its own id. in your loop, grab the page id with page_id = record['id'] then use notion_client.pages.update(page_id=page_id, properties={...}) instead of databases.update. fixed the same issue for me.

You’re mixing up database-level operations with page-level operations. You need to update individual pages within the database, not the database itself. I hit the same confusion building my file management system with Notion.

Grab the page ID from each record during your initial query, then use pages.update() instead of databases.update(). Each database row is basically a page object with its own unique ID.

Here’s how I handle this:

for record in database_data['results']:
    page_id = record['id']  # This is crucial
    video_name = record['properties']['VideoName']['rich_text'][0]['plain_text']
    folder_path = record['properties']['FolderPath']['title'][0]['plain_text']
    
    new_path = rename_video_file(video_name, folder_path)
    
    notion_client.pages.update(
        page_id=page_id,
        properties={
            'FolderPath': {
                'title': [{'text': {'content': new_path}}]
            }
        }
    )

databases.update() is for modifying database schema, not individual records. Always use pages.update() for row data.