Notion API
Every handle of the Notion fake: the notion fixture, the people and objects a test creates on it, and what they read and wait for. How to test a Notion app or agent, step by step, is in the Notion guide.
Each call is shown in every SDK's language, with its required options (the table under it lists them all). Arguments go first; options are TypeScript's trailing object, Python's keyword arguments and Rust's builder setters. The variable names are the ones the calls return elsewhere on these pages, so user is a NotionUser handle.
Besides the errors listed with each method, most methods can fail with action_requires, cross_workspace_credential, fake_actor_in_live_world, internal, invalid_argument, live_misconfigured, live_not_allowlisted, not_found, session_not_found, unauthorized, unsupported_in_live: a bad request, a closed session, or live mode refusing or misconfigured.
NotionFixture#
Returned by Session.notion().
| Field | Python / Rust | Type |
|---|---|---|
app | app | NotionIntegration |
apiUrl | api_url | string |
createUser()#
Create a person in the workspace.
const user = await notion.createUser({ name: "…" });user = await notion.create_user(name="…")let user = notion.create_user().name("…").await?;| Parameter | Python / Rust | Type | Required | |
|---|---|---|---|---|
name | name | string | yes | option |
id | id | string | no | option |
email | email | string | no | option |
avatarUrl | avatar_url | string | no | option |
token | token | string | no | option; read from CHANNELSTACK_NOTION_USER_{name}_TOKEN when left out |
Returns NotionUser.
users()#
The people this session created.
const users = await notion.users();users = await notion.users()let users = notion.users().await?;Returns NotionUsers.
createApp()#
Make another internal integration in the workspace, with its own bot user, token and webhook subscription (decision 0027), or return the one made with this name and settings. Its events go to CHANNELSTACK_NOTION_APP_<NAME>_WEBHOOK_URL, and it sees only the pages connected to it.
const integration = await notion.createApp({ name: "…" });integration = await notion.create_app(name="…")let integration = notion.create_app().name("…").await?;| Parameter | Type | Required | |
|---|---|---|---|
name | string | yes | option |
capabilities | NotionCapability[] | no | option |
events | string[] | no | option |
Returns NotionIntegration.
Live: refused with unsupported_in_live: not yet: integrations beside the built-in one aren't built live.
apps()#
The integrations this session used: the built-in one first, then each it got from createApp, in the order it first did. Another session's are not_found here.
const integrations = await notion.apps();integrations = await notion.apps()let integrations = notion.apps().await?;Returns NotionIntegrations.
pages()#
The pages this session created, a database's rows included, read again from Notion live, oldest first. Not those in the trash.
const pages = await notion.pages();pages = await notion.pages()let pages = notion.pages().await?;Returns NotionPages.
createPage()#
Create a page as seed data. The integration sees it only through connections, its own or a parent's. In the fake it sends no event; live, a real person makes it, so Notion sends page.created to a connected integration. A person creating the page sends the event in both worlds.
const page = await notion.createPage({ title: "…" });page = await notion.create_page(title="…")let page = notion.create_page().title("…").await?;| Parameter | Python / Rust | Type | Required | |
|---|---|---|---|---|
title | title | string | yes | option |
parent | parent | NotionPage | no | option |
content | content | string | { path: string } | unknown[] | no | option |
icon | icon | string | no | option |
connections | connections | NotionIntegration[] | no | option |
createdBy | created_by | NotionUser | no | option |
Returns NotionPage.
createDatabase()#
Create a database with its property schema and rows, as seed data.
const database = await notion.createDatabase({ title: "…", properties });database = await notion.create_database(title="…", properties=properties)let database = notion.create_database().title("…").properties(properties).await?;| Parameter | Type | Required | |
|---|---|---|---|
title | string | yes | option |
parent | NotionPage | no | option |
properties | Record<string, NotionPropertySchema> | yes | option |
rows | Array<Record<string, NotionPropertyValue>> | no | option |
connections | NotionIntegration[] | no | option |
Returns NotionDatabase.
Live: refused with unsupported_in_live: not yet: Notion databases, rows and properties aren't built live.
setContentUpdateDelay()#
How long Notion holds page.content_updated to batch edits, for this session (fake only). Default one second.
await notion.setContentUpdateDelay(delay);await notion.set_content_update_delay(delay)notion.set_content_update_delay(delay).await?;| Parameter | Type | Required | |
|---|---|---|---|
delay | Duration | yes | positional |
Returns nothing.
Live: refused with unsupported_in_live: Notion batches page.content_updated itself, for a time it doesn't document.
sendVerification()#
Send a subscription's verification request ({ verification_token }), as Notion does once when a subscription is created: the built-in integration's, or the one given's.
const delivery = await notion.sendVerification({ app });delivery = await notion.send_verification(app=app)let delivery = notion.send_verification().app(&app).await?;| Parameter | Type | Required | |
|---|---|---|---|
app | NotionIntegration | no | option |
Returns NotionDelivery | undefined.
Live: refused with unsupported_in_live: Notion sends the verification request once, when the subscription is created.
deliveries()#
Every webhook channelstack sent the agent for this session, with every attempt.
const deliveries = await notion.deliveries({ type: "…" });deliveries = await notion.deliveries(type="…")let deliveries = notion.deliveries().r#type("…").await?;| Parameter | Python / Rust | Type | Required | |
|---|---|---|---|---|
type | type · r#type | string | no | option |
resource | resource | NotionPage | no | option |
app | app | NotionIntegration | no | option |
Returns NotionDeliveries.
Live: refused with unsupported_in_live: Live, the platform delivers to the agent itself and channelstack isn't in the path (delivery chaos is fake-only).
calls()#
The REST calls the agent made about this session's pages, by the client's method name (comments.create).
const apiCalls = await notion.calls({ operation: "…" });api_calls = await notion.calls(operation="…")let api_calls = notion.calls().operation("…").await?;| Parameter | Type | Required | |
|---|---|---|---|
operation | string | no | option |
error | true | string | no | option |
Returns NotionApiCalls.
Live: needs proxy mode: Notion doesn't report the integration's calls; proxy mode sees them. Proxy mode doesn't read the app's calls back live yet (#24), so for now the call is refused with action_requires and the test is skipped.
waitForCall()#
Waits for the next API call from the agent after the last one this handle returned: it polls calls() and never sleeps longer than it must.
const apiCall = await notion.waitForCall({ operation: "…" });api_call = await notion.wait_for_call(operation="…")let api_call = notion.wait_for_call().operation("…").await?;| Parameter | Type | Required | |
|---|---|---|---|
operation | string | no | filter |
error | true | string | no | filter |
timeout | Duration | no | default 10s |
Returns NotionApiCall. When the time is up, it fails with what it was waiting for.
NotionIntegration#
Returned by NotionFixture.createApp().
| Field | Python / Rust | Type |
|---|---|---|
id | id | string |
name | name | string |
kind | kind | "app" |
channel | channel | "notion" |
botUserId | bot_user_id | string |
token | token | string |
webhookSecret | webhook_secret | string |
comment()#
An integration a test made starts a discussion on a page, or anchored to the block with anchor in its text, as its own comments.create would: on a page connected to it, mentioning people only. Sends comment.created to every integration that sees the page.
const comment = await integration.comment("…", { page });comment = await integration.comment("…", page=page)let comment = integration.comment("…").page(&page).await?;| Parameter | Type | Required | |
|---|---|---|---|
text | string | yes | positional |
page | NotionPage | yes | option |
anchor | string | RegExp | no | option |
Returns NotionComment.
Errors object_not_found, restricted_resource, validation_error.
Live: refused with unsupported_in_live: not yet: integrations beside the built-in one aren't built live.
reply()#
An integration a test made replies in a discussion, as comments.create with discussion_id would. Sends comment.created.
const comment = await integration.reply("…", { discussion });comment = await integration.reply("…", discussion=discussion)let comment = integration.reply("…").discussion(&discussion).await?;| Parameter | Type | Required | |
|---|---|---|---|
text | string | yes | positional |
discussion | NotionDiscussion | yes | option |
Returns NotionComment.
Errors object_not_found, restricted_resource, validation_error.
Live: refused with unsupported_in_live: not yet: integrations beside the built-in one aren't built live.
edit()#
An integration a test made edits a page's body, as its own block calls would: append, or replace it. Sends one page.content_updated once Notion's batching delay is over.
const delivery = await integration.edit(change, { page });delivery = await integration.edit(change, page=page)let delivery = integration.edit(change).page(&page).await?;| Parameter | Type | Required | |
|---|---|---|---|
change | { append?: string | { path: string } | unknown[]; replace?: string | { path: string } | unknown[] } | yes | positional |
page | NotionPage | yes | option |
Returns NotionDelivery | undefined.
Errors object_not_found, restricted_resource, validation_error.
Live: refused with unsupported_in_live: not yet: integrations beside the built-in one aren't built live.
rename()#
An integration a test made changes a page's title, as its own pages.update would. Sends page.properties_updated.
const delivery = await integration.rename("…", { page });delivery = await integration.rename("…", page=page)let delivery = integration.rename("…").page(&page).await?;| Parameter | Type | Required | |
|---|---|---|---|
title | string | yes | positional |
page | NotionPage | yes | option |
Returns NotionDelivery | undefined.
Errors object_not_found, restricted_resource, validation_error.
Live: refused with unsupported_in_live: not yet: integrations beside the built-in one aren't built live.
NotionUser#
Returned by NotionFixture.createUser().
| Field | Type |
|---|---|
id | string |
name | string |
kind | "user" |
channel | "notion" |
email | string | undefined |
comment()#
Start a discussion on a page, or anchored to the block with anchor in its text. Sends comment.created if the integration can see the page.
const comment = await user.comment("…", { page });comment = await user.comment("…", page=page)let comment = user.comment("…").page(&page).await?;| Parameter | Type | Required | |
|---|---|---|---|
text | string | yes | positional |
page | NotionPage | yes | option |
anchor | string | RegExp | no | option |
Returns NotionComment.
reply()#
Reply in a discussion. Sends comment.created.
const comment = await user.reply("…", { discussion });comment = await user.reply("…", discussion=discussion)let comment = user.reply("…").discussion(&discussion).await?;| Parameter | Type | Required | |
|---|---|---|---|
text | string | yes | positional |
discussion | NotionDiscussion | yes | option |
Returns NotionComment.
editComment()#
Edit one of this person's comments. Sends comment.updated.
const delivery = await user.editComment("…", { comment });delivery = await user.edit_comment("…", comment=comment)let delivery = user.edit_comment("…").comment(&comment).await?;| Parameter | Type | Required | |
|---|---|---|---|
text | string | yes | positional |
comment | NotionComment | yes | option |
Returns NotionDelivery | undefined.
Errors forbidden.
deleteComment()#
Delete one of this person's comments. Sends comment.deleted.
const delivery = await user.deleteComment({ comment });delivery = await user.delete_comment(comment=comment)let delivery = user.delete_comment().comment(&comment).await?;| Parameter | Type | Required | |
|---|---|---|---|
comment | NotionComment | yes | option |
Returns NotionDelivery | undefined.
Errors forbidden.
resolve()#
Resolve a discussion. Notion sends no event for it, and the API no longer lists its comments.
const delivery = await user.resolve({ discussion });delivery = await user.resolve(discussion=discussion)let delivery = user.resolve().discussion(&discussion).await?;| Parameter | Type | Required | |
|---|---|---|---|
discussion | NotionDiscussion | yes | option |
Returns NotionDelivery | undefined.
Live: refused with unsupported_in_live: not yet: Notion's API can't resolve or reopen a discussion, or say whether one is resolved.
reopen()#
Reopen a resolved discussion.
const delivery = await user.reopen({ discussion });delivery = await user.reopen(discussion=discussion)let delivery = user.reopen().discussion(&discussion).await?;| Parameter | Type | Required | |
|---|---|---|---|
discussion | NotionDiscussion | yes | option |
Returns NotionDelivery | undefined.
Live: refused with unsupported_in_live: not yet: Notion's API can't resolve or reopen a discussion, or say whether one is resolved.
createPage()#
Create a page as this person. Sends page.created if the integration can see it.
const result = await user.createPage(page);result = await user.create_page(page)let result = user.create_page(page).await?;| Parameter | Type | Required | |
|---|---|---|---|
page | { title: string; parent?: NotionPage; content?: string | { path: string } | unknown[]; icon?: string; connections?: NotionIntegration[] } | yes | positional |
Returns NotionPage.
edit()#
Edit a page's body: append, or replace it. Sends one page.content_updated once Notion's batching delay is over.
const delivery = await user.edit(change, { page });delivery = await user.edit(change, page=page)let delivery = user.edit(change).page(&page).await?;| Parameter | Type | Required | |
|---|---|---|---|
change | { append?: string | { path: string } | unknown[]; replace?: string | { path: string } | unknown[] } | yes | positional |
page | NotionPage | yes | option |
Returns NotionDelivery | undefined.
rename()#
Change a page's title. Sends page.properties_updated.
const delivery = await user.rename("…", { page });delivery = await user.rename("…", page=page)let delivery = user.rename("…").page(&page).await?;| Parameter | Type | Required | |
|---|---|---|---|
title | string | yes | positional |
page | NotionPage | yes | option |
Returns NotionDelivery | undefined.
mention()#
Mention the integration in the page body: in the block with inBlock in its text, or in a new paragraph. Sends page.content_updated after the batching delay.
const delivery = await user.mention(integration, { page });delivery = await user.mention(integration, page=page)let delivery = user.mention(&integration).page(&page).await?;| Parameter | Python / Rust | Type | Required | |
|---|---|---|---|---|
integration | integration | NotionIntegration | yes | positional |
page | page | NotionPage | yes | option |
inBlock | in_block | string | RegExp | no | option |
Returns NotionDelivery | undefined.
setProperty()#
Set a property of a database row. Sends page.properties_updated.
const delivery = await user.setProperty("…", value, { page });delivery = await user.set_property("…", value, page=page)let delivery = user.set_property("…", value).page(&page).await?;| Parameter | Type | Required | |
|---|---|---|---|
name | string | yes | positional |
value | NotionPropertyValue | yes | positional |
page | NotionPage | yes | option |
Returns NotionDelivery | undefined.
Live: refused with unsupported_in_live: not yet: Notion databases, rows and properties aren't built live.
addRow()#
Add a row to a database. Sends page.created if the integration can see the database.
const page = await user.addRow(values, { database });page = await user.add_row(values, database=database)let page = user.add_row(values).database(&database).await?;| Parameter | Type | Required | |
|---|---|---|---|
values | Record<string, NotionPropertyValue> | yes | positional |
database | NotionDatabase | yes | option |
Returns NotionPage.
Live: refused with unsupported_in_live: not yet: Notion databases, rows and properties aren't built live.
connect()#
Connect the integration to a page (Share → Connections): it sees the page and everything under it.
await user.connect(integration, { page });await user.connect(integration, page=page)user.connect(&integration).page(&page).await?;| Parameter | Type | Required | |
|---|---|---|---|
integration | NotionIntegration | yes | positional |
page | NotionPage | yes | option |
Returns nothing.
Live: needs the browser actor: no API connects a page to an integration; Notion's UI does (… → Connections). The browser actor doesn't do this yet (#47), so for now the call is refused with action_requires and the test is skipped.
disconnect()#
Remove the integration's connection from a page.
await user.disconnect(integration, { page });await user.disconnect(integration, page=page)user.disconnect(&integration).page(&page).await?;| Parameter | Type | Required | |
|---|---|---|---|
integration | NotionIntegration | yes | positional |
page | NotionPage | yes | option |
Returns nothing.
Live: needs the browser actor: no API connects a page to an integration; Notion's UI does (… → Connections). The browser actor doesn't do this yet (#47), so for now the call is refused with action_requires and the test is skipped.
NotionComment#
Returned by NotionIntegration.comment(), NotionIntegration.reply(), NotionUser.comment(), NotionUser.reply().
| Field | Python / Rust | Type |
|---|---|---|
id | id | string |
discussion | discussion | NotionDiscussion |
author | author | NotionUser | NotionIntegration |
text | text | string |
createdAt | created_at | string |
delivery | delivery | NotionDelivery | undefined |
deliveryFor()#
The comment.created delivery this comment caused to this integration (decision 0027), or nothing when it wasn't told. The comment's delivery is the built-in integration's.
const delivery = await comment.deliveryFor(app);delivery = await comment.delivery_for(app)let delivery = comment.delivery_for(&app).await?;| Parameter | Type | Required | |
|---|---|---|---|
app | NotionIntegration | yes | positional |
Returns NotionDelivery | undefined.
Live: refused with unsupported_in_live: not yet: integrations beside the built-in one aren't built live.
NotionDiscussion#
| Field | Type |
|---|---|
id | string |
page | NotionPage |
anchor | string | undefined |
comments()#
The discussion's comments, oldest first.
const comments = await discussion.comments();comments = await discussion.comments()let comments = discussion.comments().await?;Returns NotionComments.
resolved()#
Whether the discussion is resolved.
const result = await discussion.resolved();result = await discussion.resolved()let result = discussion.resolved().await?;Returns boolean.
Live: refused with unsupported_in_live: not yet: Notion's API can't resolve or reopen a discussion, or say whether one is resolved.
transcript()#
The discussion as a person reads it.
const transcript = await discussion.transcript();transcript = await discussion.transcript()let transcript = discussion.transcript().await?;Returns NotionTranscript.
waitForComment()#
Waits for the next comment after the last one this handle returned: it polls comments() and never sleeps longer than it must.
const comment = await discussion.waitForComment({ from: "my-agent" });comment = await discussion.wait_for_comment(from_="my-agent")let comment = discussion.wait_for_comment().from("my-agent").await?;| Parameter | Python / Rust | Type | Required | |
|---|---|---|---|---|
from | from_ · from | NotionUser | NotionIntegration | string | no | a handle, or a name |
timeout | timeout | Duration | no | default 10s |
Returns NotionComment. When the time is up, it fails with what it was waiting for.
latestComment()#
The latest comment, once the app is quiet. Waits for at least one: it polls comments() and never sleeps longer than it must.
const comment = await discussion.latestComment({ from: "my-agent" });comment = await discussion.latest_comment(from_="my-agent")let comment = discussion.latest_comment().from("my-agent").await?;| Parameter | Python / Rust | Type | Required | |
|---|---|---|---|---|
from | from_ · from | NotionUser | NotionIntegration | string | no | a handle, or a name |
timeout | timeout | Duration | no | default 10s |
quietFor | quiet_for | Duration | no | default 750ms |
Returns NotionComment. When the time is up, it fails with what it was waiting for.
NotionPage#
Returned by NotionFixture.createPage(), NotionUser.createPage(), NotionUser.addRow().
| Field | Type |
|---|---|
id | string |
channel | "notion" |
title | string |
url | string |
discussions()#
The page's discussions: on the page itself, and on its blocks.
const discussions = await page.discussions();discussions = await page.discussions()let discussions = page.discussions().await?;Returns NotionDiscussions.
markdown()#
The page body as Markdown, once the agent is quiet.
const result = await page.markdown();result = await page.markdown()let result = page.markdown().await?;Returns string. It reads once the app is quiet.
blocks()#
The page's blocks as the API has them, with nested blocks under children.
const blocks = await page.blocks();blocks = await page.blocks()let blocks = page.blocks().await?;Returns NotionBlocks.
property()#
A property's value as a person reads it: text, a number, option names, ids.
const propertyValue = await page.property("…");property_value = await page.property("…")let property_value = page.property("…").await?;| Parameter | Type | Required | |
|---|---|---|---|
name | string | yes | positional |
Returns NotionPropertyValue.
Live: refused with unsupported_in_live: not yet: Notion databases, rows and properties aren't built live.
children()#
The pages directly under this page.
const childPages = await page.children();child_pages = await page.children()let child_pages = page.children().await?;Returns NotionChildPages.
connections()#
The integrations that can see the page: connected to it or to a page above it.
const connections = await page.connections();connections = await page.connections()let connections = page.connections().await?;Returns NotionConnections.
transcript()#
The page and its discussions as a person reads them.
const transcript = await page.transcript();transcript = await page.transcript()let transcript = page.transcript().await?;Returns NotionTranscript.
NotionDelivery#
Returned by NotionFixture.sendVerification(), NotionIntegration.edit(), NotionIntegration.rename(), NotionUser.editComment().
| Field | Python / Rust | Type |
|---|---|---|
id | id | string |
channel | channel | "notion" |
app | app | string |
type | type · r#type | string |
entity | entity | { type: string; id: string } |
payload | payload | unknown | undefined |
attempts | attempts | DeliveryAttempt[] |
status | status | "pending" | "acknowledged" | "failed" | "timed_out" | "unreachable" |
refresh()#
Re-read a delivery: its attempts and status.
const updated = await delivery.refresh();updated = await delivery.refresh()let updated = delivery.refresh().await?;Returns NotionDelivery.
Live: refused with unsupported_in_live: Live, the platform delivers to the agent itself and channelstack isn't in the path (delivery chaos is fake-only).
redeliver()#
Send the same event again, as a retry does: the same body, the next attempt_number, signed again.
const deliveryAttempt = await delivery.redeliver();delivery_attempt = await delivery.redeliver()let delivery_attempt = delivery.redeliver().await?;Returns DeliveryAttempt.
Live: refused with unsupported_in_live: Notion has no API to redeliver a webhook.
resend()#
Send the delivery again, signed with a token that isn't the subscription's.
const deliveryAttempt = await delivery.resend({ badSignature });delivery_attempt = await delivery.resend(bad_signature=bad_signature)let delivery_attempt = delivery.resend().bad_signature(bad_signature).await?;| Parameter | Python / Rust | Type | Required | |
|---|---|---|---|---|
badSignature | bad_signature | boolean | no | option |
Returns DeliveryAttempt.
Live: refused with unsupported_in_live: Live, the platform delivers to the agent itself and channelstack isn't in the path (delivery chaos is fake-only).
settled()#
Waits for the delivery to settle: it polls refresh() and never sleeps longer than it must.
const updated = await delivery.settled();updated = await delivery.settled()let updated = delivery.settled().await?;| Parameter | Type | Required | |
|---|---|---|---|
timeout | Duration | no | default 10s |
Returns NotionDelivery. When the time is up, it fails with what it was waiting for.
NotionDatabase#
Returned by NotionFixture.createDatabase().
| Field | Type |
|---|---|
id | string |
channel | "notion" |
title | string |
url | string |
rows()#
The rows of a database, optionally only those whose properties have these values.
const rows = await database.rows();rows = await database.rows()let rows = database.rows().await?;| Parameter | Type | Required | |
|---|---|---|---|
filter | Record<string, NotionPropertyValue> | no | positional |
Returns NotionRows.
Live: refused with unsupported_in_live: not yet: Notion databases, rows and properties aren't built live.
Types#
Plain values the handles return and take.
NotionCapability#
type NotionCapability = "read_content" | "update_content" | "insert_content" | "read_comments" | "insert_comments" | "read_user_info";
NotionIntegrations#
type NotionIntegrations = NotionIntegration[];
NotionUsers#
type NotionUsers = NotionUser[];
NotionPages#
type NotionPages = NotionPage[];
NotionPropertySchema#
type NotionPropertySchema = "title" | "rich_text" | "number" | "checkbox" | "date" | "people" | "url" | "email" | { select: string[] } | { multi_select: string[] } | { status: string[] } | { relation: NotionDatabase };
NotionPropertyValue#
type NotionPropertyValue = string | number | boolean | string[] | { start: string; end?: string } | undefined;
NotionDiscussions#
type NotionDiscussions = NotionDiscussion[];
NotionBlocks#
type NotionBlocks = unknown[];
NotionChildPages#
type NotionChildPages = NotionPage[];
NotionConnections#
type NotionConnections = NotionIntegration[];
NotionTranscript#
| Field | Type |
|---|---|
entries | NotionTranscriptEntry[] |
text | string |
NotionTranscriptEntry#
| Field | Type |
|---|---|
id | string |
author | NotionPrincipal |
at | string |
text | string |
controls | string[] |
edited | boolean |
depth | number |
NotionPrincipal#
| Field | Type |
|---|---|
id | string |
name | string |
kind | "user" | "app" |
NotionRows#
type NotionRows = NotionPage[];
NotionComments#
type NotionComments = NotionComment[];
NotionDeliveries#
type NotionDeliveries = NotionDelivery[];
NotionApiCalls#
type NotionApiCalls = NotionApiCall[];
NotionApiCall#
| Field | Python / Rust | Type |
|---|---|---|
id | id | string |
channel | channel | "notion" |
operation | operation | string |
method | method | string |
path | path | string |
at | at | string |
durationMs | duration_ms | number |
request | request | unknown | undefined |
responseStatus | response_status | number |
response | response | unknown | undefined |
error | error | string | undefined |