π οΈ Lesson 8.3: The Notion API & Webhooks β Optional Deep Dive
This is the one lesson in the course written for the tinkerers. If the word "API" makes your eyes glaze, that is completely fine β you can skip this whole lesson and lose nothing. But if you've ever wondered how Zapier, custom dashboards, and scripts actually talk to Notion, come on in. We'll keep the code tiny and explain every line.
π This lesson is totally optional β skip guilt-free
Nothing else in this course depends on the API. You can build a superb, complete Notion workspace and never see a line of code. This lesson exists purely for the curious and technically-minded. If that's not you today, jump straight to Lesson 9.1 β Mobile, Multi-Device & the Web Clipper with a clear conscience. Still here? Great β let's demystify it together.
π What You'll Learn
By the end of this (optional!) lesson, you will be able to:
- Explain in plain words what the Notion API is and what you'd use it for
- Create an internal integration and copy its secret token
- Do the step everyone misses: share a database with your integration
- Read a tiny
curland JavaScriptfetchexample that queries a database and creates a page - Understand webhooks and rate limits at a high level, and know where to learn more
β±οΈ Estimated Time: 70 minutes (optional; less if you just read)
π― Project (optional/simplified): Create an integration, connect it to a test database, and β if you're comfortable β run the provided query snippet. Or just read and understand the flow.
In This Lesson
What Is the API (In Plain Words)?
An API (Application Programming Interface) is just a doorway that lets one program talk to another. The Notion API is the official doorway a script β or a service like Zapier β uses to read from and write to your workspace without a human clicking around. Where you use the Notion app, a program uses the API.
Think of it like a drive-through window at a restaurant. You (the script) pull up, hand over an order slip written in a format the kitchen understands (a request), and the kitchen hands back your food (a response). The Notion API is that window: your program sends a neatly-formatted request, Notion sends back neatly-formatted data.
or Zapier/Make"] -->|"request
(with your token)"| A["πͺ Notion API
api.notion.com"] A -->|"reads / writes"| W["π Your workspace
pages & databases"] W -->|"data"| A A -->|"response (JSON)"| S
What can it do? Query a database (get me all tasks that are overdue), create a page (add a new task), update properties (mark this one done), and read page content. It's how people build custom dashboards, sync Notion with a spreadsheet, or auto-post from a form.
π§ Mindset
You will not memorize this, and you don't need to. Everyone β professional developers included β keeps the docs open and copies examples. If a snippet errors on your first try, that's not failure, it's the normal loop: read the error, tweak one thing, run again. The goal today is to understand the flow, not to become a programmer. Read as far as is fun and stop whenever you like.
π Definition
Internal integration: A little "app" you register inside your own workspace so a script can act on your behalf. It comes with a secret token (a password for the API). "Internal" means it's just for your workspace β as opposed to a "public" integration that other people install, which is a much bigger project you don't need here.
Step 1: Create an Integration & Token
Everything starts with an integration and its token. Here's the flow:
- Go to developers.notion.com and open notion.com/my-integrations (there's a big "View my integrations" link).
- Click New integration. Give it a name (e.g. "My Test Script"), pick the workspace, and save.
- On the integration's page, find the Internal Integration Secret and click
Show, then copy it. This is your token β it starts with something like
secret_orntn_.
β οΈ Treat your token like a password
Anyone with this token can read and change everything you've shared with the integration. Never paste it into a public page, a screenshot, a GitHub repo, or a chat. If it ever leaks, go back to the integration and refresh (rotate) the secret immediately β that invalidates the old one. In real projects you'd store it in an environment variable, never hard-coded.
The API is free to use on any plan for your own data, but it's rate-limited (more on that below), and some workspace-level controls over who may add integrations lean toward Business/Enterprise admin settings. For a personal workspace on the Free plan, you can create an internal integration and start experimenting at no cost.
Step 2: Share a Database (the step everyone misses)
Here's the gotcha that trips up almost everyone the first time: creating an integration does not give it access to anything. By default it can see nothing in your workspace. You have to explicitly connect (share) each page or database with the integration β a deliberate safety design so a token can't roam your whole workspace.
To connect a database to your integration:
- Open the database (or a page) in Notion.
- Click the β― menu at the top-right.
- Choose Connections (sometimes "Connect to" / "Add connections").
- Pick your integration by name. Done β it can now read and write that database.
π« If your API call returns "object not found"
Nine times out of ten it means you forgot this step, or you connected a different page. The integration literally cannot see anything you haven't shared with it. Re-open the database's β― β Connections and confirm your integration is listed. This one step fixes the vast majority of "why isn't it working?" moments.
You'll also need the database's ID for API calls. Open the database as a full page and
copy its URL β the long string of letters and numbers before the ? is the database ID.
https://www.notion.so/myworkspace/a1b2c3d4e5f6...?v=...
βββ this part is the database ID βββ
Step 3: A Tiny Example (curl & fetch)
Now the fun part. Every Notion API request needs three things in common β think of them as the envelope your order slip goes in:
- An Authorization header carrying your token (proves it's you).
- A Notion-Version header (tells the API which version of its rules to use).
- A Content-Type header of
application/jsonwhen you send data.
π Query a database with curl
curl is a command-line tool for sending web requests β great for a quick test. This asks
Notion for the rows in a database:
curl -X POST 'https://api.notion.com/v1/databases/YOUR_DATABASE_ID/query' \
-H 'Authorization: Bearer YOUR_SECRET_TOKEN' \
-H 'Notion-Version: 2022-06-28' \
-H 'Content-Type: application/json'
Line by line:
-X POST β¦ /databases/YOUR_DATABASE_ID/queryβ send a POST request to the "query this database" endpoint. Swap in your real database ID.-H 'Authorization: Bearer YOUR_SECRET_TOKEN'β your token, prefixed with the wordBearer. This is how Notion knows who's asking.-H 'Notion-Version: 2022-06-28'β the API version. Always include it; check the docs for the current recommended value.-H 'Content-Type: application/json'β tells Notion you're speaking JSON.
Run that and Notion sends back JSON listing your rows. That's a real, working read from your workspace.
β Create a page with JavaScript fetch
fetch is the built-in way to make web requests in JavaScript. This adds a new row (a
page) to a database, setting its Name title property:
const token = "YOUR_SECRET_TOKEN";
const databaseId = "YOUR_DATABASE_ID";
const response = await fetch("https://api.notion.com/v1/pages", {
method: "POST",
headers: {
"Authorization": `Bearer ${token}`,
"Notion-Version": "2022-06-28",
"Content-Type": "application/json"
},
body: JSON.stringify({
parent: { database_id: databaseId },
properties: {
Name: {
title: [ { text: { content: "Created from a script!" } } ]
}
}
})
});
const data = await response.json();
console.log(data.id ? "Created page: " + data.id : data);
Walking through it:
- The
tokenanddatabaseIdlines hold your two secrets/IDs (in real code, read the token from an environment variable, not a literal string). fetch("β¦/v1/pages", { method: "POST", β¦ })β POST to the "create a page" endpoint.- The
headersare the same envelope as before: your token, the version, and JSON content-type. body: JSON.stringify({ β¦ })β the actual order.parentsays which database the new page belongs to;propertiessets its values. HereNameis the title property β the odd nested shape (title β text β content) is just how Notion represents rich text.- The last two lines read the JSON response and log the new page's ID (or the error, so you can see what went wrong).
β Pro Tip
You don't have to build these requests by hand. Notion publishes official SDKs
(a JavaScript one, @notionhq/client, and community Python ones) that wrap all this in
tidy functions like notion.pages.create(...). Start with the raw request to understand
what's happening, then reach for an SDK once the flow makes sense β your future self will thank you.
π‘ For non-coders: you can stop here
If those snippets look like alphabet soup, that's genuinely okay β you now understand the shape of it: authenticate with a token, point at a database, send or receive JSON. That mental model is enough to talk to a developer, configure a Zapier step, or decide the API isn't for you. Understanding the flow is a complete, worthwhile outcome. π
Webhooks, Rate Limits & Learning More
π‘ Webhooks (high level)
The examples above are you asking Notion ("give me the rows"). A webhook flips that around: it's Notion telling you when something happens. You register a URL, and Notion sends a little message to it whenever, say, a page is updated β so your script can react instantly instead of polling over and over. Notion's own database automations can also trigger a webhook to an outside service. You don't need webhooks to get started; just know the direction is reversed β Notion pushes to you.
π’ Rate limits
The API is rate-limited β roughly a few requests per second per integration β so no
script can hammer Notion. If you send too many too fast, you'll get a 429 Too Many Requests
response; the polite fix is to slow down and retry after a moment. For casual tinkering you'll almost
never hit it; it matters when syncing thousands of rows.
π Where to learn more
The single best resource is the official developer docs at developers.notion.com β they have a "Getting started" guide, an API reference for every endpoint, and copy-pasteable examples. Keep it open beside you; that's exactly how the pros work.
π Going Further (optional)
If this lit a spark, a fun first real project is a script that reads your task database each morning and prints what's due today, or one that appends a row to a "Log" database. Small, useful, and it exercises both reading and writing. Build the smallest thing that does something real β that's how every developer got started.
π― Project: Connect an Integration (Optional / Simplified)
Two ways to do this project β pick the one that fits your comfort. Path A is read-and-understand (no code). Path B actually runs a snippet. Both count as complete.
ποΈ Set up the doorway (and optionally walk through it)
Objective: Experience the real setup flow β integration β token β share a database β and, if you like, make one live API call.
Instructions (about 20β30 minutes):
- (3 min) Create a throwaway database called API Test with a couple of rows. Never test on data you'd hate to lose.
- (5 min) Go to notion.com/my-integrations, create a New integration, and copy its secret token somewhere private.
- (3 min) Open the API Test database β β― β Connections β connect your integration. (This is the step everyone forgets!)
- (2 min) Copy the database ID from its URL.
- Path A β read & understand (0 min of code): Re-read the curl and fetch examples with your token and ID in mind. Trace what each line does. That's a valid finish β you understand the flow.
- Path B β run it (10 min, if comfortable): Paste the
curlcommand into a terminal with your real token and database ID, and run it. You should get JSON back listing your rows. Celebrate β you just talked to the Notion API!
π‘ Hint β the smallest possible curl test
The simplest call just fetches info about your integration's access β a good "is my token even valid?" check:
curl 'https://api.notion.com/v1/users/me' \
-H 'Authorization: Bearer YOUR_SECRET_TOKEN' \
-H 'Notion-Version: 2022-06-28'
If that returns JSON about your integration (not an error), your token works. Then try the
database query. Getting object not found? You forgot to share the database β go back
to β― β Connections.
β Project Completion Checklist
- You created a test database (not real, important data)
- You created an integration and copied its token privately
- You connected the integration to the database via β― β Connections
- You copied the database ID from its URL
- You either traced the snippets line-by-line (Path A) or ran a live call and got JSON back (Path B)
π― Quick Quiz
Question 1: You created an integration but your API call returns "object not found." What did you most likely skip?
Question 2: What's the difference between calling the API and a webhook?
Best Practices for API Tinkering
β Do's
- Test on a throwaway database. Never point your first script at real data.
- Keep the docs open. Copying examples from developers.notion.com is normal, not cheating.
- Guard your token. Store it in an environment variable; rotate it if it leaks.
β Don'ts
- Don't paste your token into public pages, screenshots, or repos.
- Don't forget to share the database β the integration sees nothing until you do.
- Don't feel obligated. If code isn't fun for you, understanding the flow is a complete win.
π Learning Journal
Keep a learning journal β for this course, the best place is inside your own Notion. After each lesson, take a few minutes to write down:
- Key concepts you learned
- Techniques that clicked for you
- Questions or confusion points to revisit
- Ideas you want to try
- Your progress and feelings about learning this
βοΈ This lesson's prompt: Did the API feel exciting, intimidating, or irrelevant to you β and that's all a valid answer! If it sparked something, jot one tiny script idea you might try. If it didn't, note that you understand the flow well enough to move on with confidence.
π Lesson Summary
π Key Takeaways
- The API is a doorway that lets scripts and services read from and write to your workspace β the same doorway Zapier uses.
- You start by creating an internal integration at notion.com/my-integrations and copying its secret token (guard it like a password).
- The step everyone misses: share (connect) each database with the integration via β― β Connections, or it can see nothing.
- Every request carries three headers β Authorization (token), Notion-Version, and Content-Type β and you saw a tiny
curlquery and afetchthat creates a page. - Webhooks reverse the direction (Notion notifies you), the API is rate-limited, and developers.notion.com is where to learn more.
π What You've Accomplished
Whether you ran the code or just followed along, you now understand something most Notion users never see: how the automations and integrations actually talk to Notion. That demystifies the whole ecosystem β Zapier, custom dashboards, community tools β and, if you're the type, opens the door to building your own. And if you decided coding isn't for you, you made that call from understanding, not intimidation. Both are wins.
β Common Questions at This Stage
Do I need to pay to use the API?
No β you can create an internal integration and use the API for your own data on the Free plan. It's rate-limited but free. Some admin controls over integrations lean toward Business/Enterprise, and third-party services built on the API (like Zapier) have their own pricing.
Is it safe? I don't want to break my workspace.
Yes, if you're careful. An integration can only touch databases you explicitly connect to it, so practice on a throwaway "API Test" database and your real data stays untouched. Guard your token, and if it ever leaks, rotate it from the integration's settings.
I'm not a coder β was this lesson pointless for me?
Not at all. Understanding the flow β token, share the database, send/receive JSON β is genuinely useful even if you never write a script. It helps you configure no-code automators, talk to a developer, and judge which community tools to trust. And it was clearly marked optional for exactly this reason.
π Looking Ahead
That wraps the automation-and-integration module. Next we come back down to earth β and into your pocket: using Notion on mobile and across devices, and revisiting the Web Clipper for capturing ideas wherever you are.
β Before the Next Lesson
- Delete your test integration and API Test database if you don't need them
- Bookmark developers.notion.com if the API interested you
- Write your Learning Journal entry for this lesson
π Additional Resources
- developers.notion.com β official API docs & getting-started guide
- Notion Help Center β connections & integrations
- r/Notion β API projects & help from the community
π Encouragement for the Journey
You just peeked behind the curtain β and it turned out to be a friendly doorway, not a wall. Curious enough to run a snippet? You're now, technically, someone who has programmed Notion. Preferred to read? You understand the machinery better than most. Either way: onward. π οΈ