DEV Community

Alex Spinov
Alex Spinov

Posted on

Notion Has a Free API — Build Custom Dashboards and Automate Your Workflow

Notion Is Not Just a Note App

Notion API lets you programmatically read, create, and update pages, databases, and blocks. Free for personal use, included in all plans.

Setup

  1. Go to notion.so/my-integrations
  2. Create new integration
  3. Copy the API key
  4. Share your database/page with the integration
import requests

TOKEN = "your_notion_api_key"
HEADERS = {
    "Authorization": f"Bearer {TOKEN}",
    "Content-Type": "application/json",
    "Notion-Version": "2022-06-28"
}
Enter fullscreen mode Exit fullscreen mode

Query a Database

def query_database(db_id, filter_obj=None):
    data = {}
    if filter_obj:
        data["filter"] = filter_obj
    r = requests.post(f"https://api.notion.com/v1/databases/{db_id}/query",
                      headers=HEADERS, json=data)
    results = r.json()["results"]
    return [{"id": p["id"], "props": {k: v for k, v in p["properties"].items()}}
            for p in results]

# Get all items where Status = "Done"
items = query_database("your_db_id", {
    "property": "Status",
    "status": {"equals": "Done"}
})
Enter fullscreen mode Exit fullscreen mode

Create a Page

def create_page(db_id, title, status="Not started"):
    data = {
        "parent": {"database_id": db_id},
        "properties": {
            "Name": {"title": [{"text": {"content": title}}]},
            "Status": {"status": {"name": status}}
        }
    }
    r = requests.post("https://api.notion.com/v1/pages",
                      headers=HEADERS, json=data)
    return r.json()["id"]

page_id = create_page("db_id", "New task from Python")
Enter fullscreen mode Exit fullscreen mode

Add Content to a Page

def add_blocks(page_id, blocks):
    r = requests.patch(f"https://api.notion.com/v1/blocks/{page_id}/children",
                       headers=HEADERS, json={"children": blocks})
    return r.json()

add_blocks(page_id, [
    {"type": "heading_2", "heading_2": {
        "rich_text": [{"text": {"content": "Summary"}}]
    }},
    {"type": "paragraph", "paragraph": {
        "rich_text": [{"text": {"content": "This was created via the API."}}]
    }},
    {"type": "bulleted_list_item", "bulleted_list_item": {
        "rich_text": [{"text": {"content": "First point"}}]
    }}
])
Enter fullscreen mode Exit fullscreen mode

Real Automation Ideas

  1. Daily standup bot — create a page every morning with template
  2. CRM — add leads from email/forms directly to Notion database
  3. Content calendar — sync Dev.to articles to Notion tracker
  4. Project dashboard — aggregate data from multiple databases
  5. Meeting notes — auto-create pages with attendees and agenda

Rate Limits

  • 3 requests per second per integration
  • No daily limit
  • Pagination for large databases (100 items per page)

More API tutorials | GitHub


Need custom dev tools, scrapers, or API integrations? I build automation for dev teams. Email spinov001@gmail.com — or explore awesome-web-scraping.


More from me: 10 Dev Tools I Use Daily | 77 Scrapers on a Schedule | 150+ Free APIs
NEW: I Ran an AI Agent for 16 Days — What Works

Top comments (0)