How to add a quote block to a Notion database page using API

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?

Looking at your code, the issue is likely with how you’re formatting the page ID in the URL. Notion page IDs returned from the database query often contain hyphens, but sometimes the API expects them without hyphens or in a different format. I encountered this exact problem when working with database pages versus regular pages. Try removing the hyphens from the target_page_id before using it in the URL: ```python
target_page_id = json_data[‘results’][0][‘id’].replace(‘-’, ‘’)

check your notion version header - i had same error and switching to “2022-02-22” fixed it. also try logging the actual target_page_id to see if its getting retrieved correctly, sometimes database pages dont return proper ids

I had a similar issue last month and the problem was with the quote block structure. The text property in your quote block should be ‘rich_text’ instead of ‘text’. Here’s what fixed it for me:

'quote': {
    'rich_text': [
        {
            'type': 'text',
            'text': {
                'content': 'Here is my custom quote text.'
            }
        }
    ]
}

Notion’s API documentation can be confusing about this since different block types use different property names. Also make sure you’re using the latest API version in your headers. The ‘Invalid request URL’ error often masks validation issues with the payload structure rather than the actual URL being wrong.