# Notion Routing Reference

**App name:** `notion`
**Base URL proxied:** `api.notion.com`

## Required Headers

All Notion API requests require:
```
Notion-Version: [REDACTED_PHONE]
```

## API Path Pattern

```
/notion/v1/{endpoint}
```

## Key Concept: Databases vs Data Sources

In API version [REDACTED_PHONE], databases and data sources are separate concepts:

| Concept | Description | Use For |
|---------|-------------|---------|
| **Database** | Container that can hold multiple data sources | Creating databases, getting data_source IDs |
| **Data Source** | Schema and data within a database | Querying, updating schema, updating properties |

Most existing databases have one data source. Use `GET /databases/{id}` to get the `data_source_id`, then use `/data_sources/` endpoints for all operations.

## Common Endpoints

### Search

Search for pages:
```bash
POST /notion/v1/search
Content-Type: application/json
Notion-Version: [REDACTED_PHONE]

{
  "query": "meeting notes",
  "filter": {"property": "object", "value": "page"}
}
```

Search for data sources:
```bash
POST /notion/v1/search
Content-Type: application/json
Notion-Version: [REDACTED_PHONE]

{
  "filter": {"property": "object", "value": "data_source"}
}
```

With pagination:
```bash
POST /notion/v1/search
Content-Type: application/json
Notion-Version: [REDACTED_PHONE]

{
  "page_size": 10,
  "start_cursor": "CURSOR_FROM_PREVIOUS_RESPONSE"
}
```

### Data Sources

Use data source endpoints for querying, getting schema, and updates.

#### Get Data Source
```bash
GET /notion/v1/data_sources/{dataSourceId}
Notion-Version: [REDACTED_PHONE]
```

Returns full schema with `properties` field.

#### Query Data Source
```bash
POST /notion/v1/data_sources/{dataSourceId}/query
Content-Type: application/json
Notion-Version: [REDACTED_PHONE]

{
  "filter": {
    "property": "Status",
    "select": {"equals": "Active"}
  },
  "sorts": [
    {"property": "Created", "direction": "descending"}
  ],
  "page_size": 100
}
```

#### Update Data Source (title, schema, properties)
```bash
PATCH /notion/v1/data_sources/{dataSourceId}
Content-Type: application/json
Notion-Version: [REDACTED_PHONE]

{
  "title": [{"type": "text", "text": {"content": "Updated Title"}}],
  "properties": {
    "NewColumn": {"rich_text": {}}
  }
}
```

### Databases

Database endpoints are only needed for **creating** databases and **discovering** data source IDs.

#### Get Database (to find data_source_id)
```bash
GET /notion/v1/databases/{databaseId}
Notion-Version: [REDACTED_PHONE]
```

Response includes `data_sources` array:
```json
{
  "id": "database-id",
  "object": "database",
  "data_sources": [{"id": "data-source-id", "name": "Database Name"}]
}
```

**Note:** This endpoint returns `properties: null`. Use `GET /data_sources/{id}` to get the schema.

#### Create Database
```bash
POST /notion/v1/databases
Content-Type: application/json
Notion-Version: [REDACTED_PHONE]

{
  "parent": {"type": "page_id", "page_id": "PARENT_PAGE_ID"},
  "title": [{"type": "text", "text": {"content": "New Database"}}],
  "properties": {
    "Name": {"title": {}},
    "Status": {"select": {"options": [{"name": "Active"}, {"name": "Done"}]}}
  }
}
```

**Important:** Cannot create databases via `/data_sources` endpoint.

### Pages

#### Get Page
```bash
GET /notion/v1/pages/{pageId}
Notion-Version: [REDACTED_PHONE]
```

#### Create Page in Data Source
Use `data_source_id` (not `database_id`) as parent:
```bash
POST /notion/v1/pages
Content-Type: application/json
Notion-Version: [REDACTED_PHONE]

{
  "parent": {"data_source_id": "DATA_SOURCE_ID"},
  "properties": {
    "Name": {"title": [{"text": {"content": "New Page"}}]},
    "Status": {"select": {"name": "Active"}}
  }
}
```

#### Create Child Page (under another page)
```bash
POST /notion/v1/pages
Content-Type: application/json
Notion-Version: [REDACTED_PHONE]

{
  "parent": {"page_id": "PARENT_PAGE_ID"},
  "properties": {
    "title": {"title": [{"text": {"content": "Child Page"}}]}
  }
}
```

#### Update Page Properties
```bash
PATCH /notion/v1/pages/{pageId}
Content-Type: application/json
Notion-Version: [REDACTED_PHONE]

{
  "properties": {
    "Status": {"select": {"name": "Done"}}
  }
}
```

#### Archive Page
```bash
PATCH /notion/v1/pages/{pageId}
Content-Type: application/json
Notion-Version: [REDACTED_PHONE]

{
  "archived": true
}
```

### Blocks

#### Get Block
```bash
GET /notion/v1/blocks/{blockId}
Notion-Version: [REDACTED_PHONE]
```

#### Get Block Children
```bash
GET /notion/v1/blocks/{blockId}/children
Notion-Version: [REDACTED_PHONE]
```

#### Append Block Children
```bash
PATCH /notion/v1/blocks/{blockId}/children
Content-Type: application/json
Notion-Version: [REDACTED_PHONE]

{
  "children": [
    {
      "object": "block",
      "type": "paragraph",
      "paragraph": {
        "rich_text": [{"type": "text", "text": {"content": "New paragraph"}}]
      }
    },
    {
      "object": "block",
      "type": "heading_2",
      "heading_2": {
        "rich_text": [{"type": "text", "text": {"content": "Heading"}}]
      }
    }
  ]
}
```

#### Update Block
```bash
PATCH /notion/v1/blocks/{blockId}
Content-Type: application/json
Notion-Version: [REDACTED_PHONE]

{
  "paragraph": {
    "rich_text": [{"text": {"content": "Updated text"}}]
  }
}
```

#### Delete Block
```bash
DELETE /notion/v1/blocks/{blockId}
Notion-Version: [REDACTED_PHONE]
```

### Users

#### List Users
```bash
GET /notion/v1/users
Notion-Version: [REDACTED_PHONE]
```

#### Get User by ID
```bash
GET /notion/v1/users/{userId}
Notion-Version: [REDACTED_PHONE]
```

#### Get Current User (Bot)
```bash
GET /notion/v1/users/me
Notion-Version: [REDACTED_PHONE]
```

## Filter Operators

- `equals`, `does_not_equal`
- `contains`, `does_not_contain`
- `starts_with`, `ends_with`
- `is_empty`, `is_not_empty`
- `greater_than`, `less_than`, `greater_than_or_equal_to`, `less_than_or_equal_to`

## Block Types

Common block types for appending:
- `paragraph` - Text paragraph
- `heading_1`, `heading_2`, `heading_3` - Headings
- `bulleted_list_item`, `numbered_list_item` - List items
- `to_do` - Checkbox item
- `code` - Code block
- `quote` - Quote block
- `divider` - Horizontal divider

## Migration from Older API Versions

| Old ([REDACTED_PHONE]) | New ([REDACTED_PHONE]) |
|------------------|------------------|
| `POST /databases/{id}/query` | `POST /data_sources/{id}/query` |
| `GET /databases/{id}` for schema | `GET /data_sources/{id}` for schema |
| `PATCH /databases/{id}` for schema | `PATCH /data_sources/{id}` for schema |
| Parent: `{"database_id": "..."}` | Parent: `{"data_source_id": "..."}` |
| Search filter: `"database"` | Search filter: `"data_source"` |

## Notes

- Use `GET /databases/{id}` to discover `data_source_id`, then use `/data_sources/` for all operations
- Creating databases still requires `POST /databases` endpoint
- Parent objects for create database require `type` field: `{"type": "page_id", "page_id": "..."}`
- All IDs are UUIDs (with or without hyphens)
- Delete blocks returns the block with `archived: true`

## Resources

- [API Introduction](https://developers.notion.com/reference/intro)
- [Search](https://developers.notion.com/reference/post-search.md)
- [Query Database](https://developers.notion.com/reference/post-database-query.md)
- [Get Database](https://developers.notion.com/reference/retrieve-a-database.md)
- [Create Database](https://developers.notion.com/reference/create-a-database.md)
- [Get Page](https://developers.notion.com/reference/retrieve-a-page.md)
- [Create Page](https://developers.notion.com/reference/post-page.md)
- [Update Page](https://developers.notion.com/reference/patch-page.md)
- [Get Block Children](https://developers.notion.com/reference/get-block-children.md)
- [Append Block Children](https://developers.notion.com/reference/patch-block-children.md)
- [List Users](https://developers.notion.com/reference/get-users.md)
- [Filter Reference](https://developers.notion.com/reference/post-database-query-filter.md)
- [LLM Reference](https://developers.notion.com/llms.txt)
- [Version Reference](https://developers.notion.com/guides/get-started/upgrade-guide-[REDACTED_PHONE])