I’m trying to add a quote block to an existing page in my Notion database but keep running into issues. The page retrieval works fine, but when I attempt to create and append the quote block, I get an “Invalid request URL” error. I’m pretty sure my URL is correct since I copied it from Notion directly.
The error happens specifically when trying to create the block, and my console shows “Error creating the block” from the print statement. Here’s my current approach:
import requests
import json
# Authentication setup
api_key = "................."
db_id = "............."
# Get pages from database
fetch_pages_endpoint = f'https://api.notion.com/v1/databases/{db_id}/query'
request_headers = {
"Authorization": "Bearer " + api_key,
"Content-Type": "application/json",
"Notion-Version": "2022-06-28",
}
page_response = requests.post(fetch_pages_endpoint, headers=request_headers)
if page_response.status_code == 200:
json_data = page_response.json()
# Get first available page
if len(json_data['results']) > 0:
target_page_id = json_data['results'][0]['id']
# Block creation endpoint
add_block_endpoint = f'https://api.notion.com/v1/blocks/{target_page_id}/children'
# Quote block structure
new_block_data = {
'children': [
{
'object': 'block',
'type': 'quote',
'quote': {
'text': [
{
'type': 'text',
'text': {
'content': 'Here is my custom quote text.'
}
}
]
}
}
]
}
# Send block creation request
block_response = requests.post(add_block_endpoint, headers=request_headers, data=json.dumps(new_block_data))
# Verify result
if block_response.status_code == 200:
print('Quote block added successfully to database page.')
else:
print('Error creating the block:', block_response.status_code, block_response.text)
else:
print('No pages found in database.')
else:
print('Failed to fetch pages:', page_response.status_code, page_response.text)
Any ideas what might be causing this URL error?