I’m having trouble fetching all records from my Notion database through their API. My database has over 300 entries, but I keep hitting a wall when trying to get them all.
I know Notion limits each request to 100 records, so I wrote code to handle pagination using cursors. It works fine for the first 3 pages (300 records total), but then I get this error:
{'errorId': '94d72e18-3501-4976-8c61-1c66177045d3',
'name': 'PayloadTooLargeError',
'message': 'Request body too large.'}
Here’s my pagination function:
def fetch_all_pages(response):
api_url = f"https://api.notion.com/v1/databases/{db_id}/query"
cursor = response['next_cursor']
try:
while response['has_more']:
response['start_cursor'] = cursor
payload = json.dumps(response)
# Request next batch of 100 items
next_response = requests.post(
api_url, headers=request_headers, data=payload).json()
response["results"] += next_response["results"]
cursor = next_response['next_cursor']
if cursor is None:
break
except:
pass
return response
Is there actually a 300-record limit in Notion’s API? Has anyone found a way around this issue?