How to search for specific page by name in Notion database using Python

I want to modify the cover images for specific pages in my Notion database. When I try to search for a particular page using the search endpoint, it returns every page in the database rather than filtering by my search term.

api_url = f"https://api.notion.com/v1/databases/{db_id}/query"
filter_params = {
    "filter": {
        "and": [
            {
                "property": "Show Name",
                "text": {
                    "contains": "sample_series"
                }
            }
        ]
    }
}
response = requests.post(api_url, headers=request_headers, json=filter_params)
result = response.json()
print(result)

I need to get the correct page_id so I can use the Update Page API to change the page cover. What am I doing wrong with my filtering approach?

Had this exact bug last week! The problem’s with property types - Notion’s API wants “title” for title fields, not “text”. Also check your property name spelling. I wasted hours debugging because I wrote “ShowName” instead of “Show Name” lol. Fix that and your filter will work fine to get the page ID.

Your filter structure looks right, but it’s probably a property type issue. Notion’s API is picky about matching exact property types in filters. If “Show Name” is a title property, use "title" instead of "text". Rich text properties need "rich_text". Also check the property name matches exactly - spaces, special characters, everything. I’d run a test query without filters first to see the raw response. That’ll show you the exact property type and name format you need.

Sounds like a property type issue. I hit this same problem with Notion’s API before. Try switching “text” to “title” if “Show Name” is actually a title property, or use “rich_text” for regular text properties. Also make sure your property name matches exactly - Notion’s case-sensitive about that stuff. Quick tip: run a simple query without filters first to see your database structure and confirm the property types. Once you fix the filtering, you’ll get just the matching pages back and can grab the page_id from the results to use with the Update Page API.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.