Docs menu

Platform APIs

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().

FieldPython / RustType
appappNotionIntegration
apiUrlapi_urlstring

createUser()#

Create a person in the workspace.

const user = await notion.createUser({ name: "…" });
ParameterPython / RustTypeRequired
namenamestringyesoption
ididstringnooption
emailemailstringnooption
avatarUrlavatar_urlstringnooption
tokentokenstringnooption; read from CHANNELSTACK_NOTION_USER_{name}_TOKEN when left out

Returns NotionUser.

users()#

The people this session created.

const users = await notion.users();

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: "…" });
ParameterTypeRequired
namestringyesoption
capabilitiesNotionCapability[]nooption
eventsstring[]nooption

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();

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();

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: "…" });
ParameterPython / RustTypeRequired
titletitlestringyesoption
parentparentNotionPagenooption
contentcontentstring | { path: string } | unknown[]nooption
iconiconstringnooption
connectionsconnectionsNotionIntegration[]nooption
createdBycreated_byNotionUsernooption

Returns NotionPage.

createDatabase()#

Create a database with its property schema and rows, as seed data.

const database = await notion.createDatabase({ title: "…", properties });
ParameterTypeRequired
titlestringyesoption
parentNotionPagenooption
propertiesRecord<string, NotionPropertySchema>yesoption
rowsArray<Record<string, NotionPropertyValue>>nooption
connectionsNotionIntegration[]nooption

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);
ParameterTypeRequired
delayDurationyespositional

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 });
ParameterTypeRequired
appNotionIntegrationnooption

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: "…" });
ParameterPython / RustTypeRequired
typetype · r#typestringnooption
resourceresourceNotionPagenooption
appappNotionIntegrationnooption

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: "…" });
ParameterTypeRequired
operationstringnooption
errortrue | stringnooption

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: "…" });
ParameterTypeRequired
operationstringnofilter
errortrue | stringnofilter
timeoutDurationnodefault 10s

Returns NotionApiCall. When the time is up, it fails with what it was waiting for.

NotionIntegration#

Returned by NotionFixture.createApp().

FieldPython / RustType
ididstring
namenamestring
kindkind"app"
channelchannel"notion"
botUserIdbot_user_idstring
tokentokenstring
webhookSecretwebhook_secretstring

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 });
ParameterTypeRequired
textstringyespositional
pageNotionPageyesoption
anchorstring | RegExpnooption

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 });
ParameterTypeRequired
textstringyespositional
discussionNotionDiscussionyesoption

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 });
ParameterTypeRequired
change{ append?: string | { path: string } | unknown[]; replace?: string | { path: string } | unknown[] }yespositional
pageNotionPageyesoption

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 });
ParameterTypeRequired
titlestringyespositional
pageNotionPageyesoption

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().

FieldType
idstring
namestring
kind"user"
channel"notion"
emailstring | 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 });
ParameterTypeRequired
textstringyespositional
pageNotionPageyesoption
anchorstring | RegExpnooption

Returns NotionComment.

reply()#

Reply in a discussion. Sends comment.created.

const comment = await user.reply("…", { discussion });
ParameterTypeRequired
textstringyespositional
discussionNotionDiscussionyesoption

Returns NotionComment.

editComment()#

Edit one of this person's comments. Sends comment.updated.

const delivery = await user.editComment("…", { comment });
ParameterTypeRequired
textstringyespositional
commentNotionCommentyesoption

Returns NotionDelivery | undefined.

Errors forbidden.

deleteComment()#

Delete one of this person's comments. Sends comment.deleted.

const delivery = await user.deleteComment({ comment });
ParameterTypeRequired
commentNotionCommentyesoption

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 });
ParameterTypeRequired
discussionNotionDiscussionyesoption

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 });
ParameterTypeRequired
discussionNotionDiscussionyesoption

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);
ParameterTypeRequired
page{ title: string; parent?: NotionPage; content?: string | { path: string } | unknown[]; icon?: string; connections?: NotionIntegration[] }yespositional

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 });
ParameterTypeRequired
change{ append?: string | { path: string } | unknown[]; replace?: string | { path: string } | unknown[] }yespositional
pageNotionPageyesoption

Returns NotionDelivery | undefined.

rename()#

Change a page's title. Sends page.properties_updated.

const delivery = await user.rename("…", { page });
ParameterTypeRequired
titlestringyespositional
pageNotionPageyesoption

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 });
ParameterPython / RustTypeRequired
integrationintegrationNotionIntegrationyespositional
pagepageNotionPageyesoption
inBlockin_blockstring | RegExpnooption

Returns NotionDelivery | undefined.

setProperty()#

Set a property of a database row. Sends page.properties_updated.

const delivery = await user.setProperty("…", value, { page });
ParameterTypeRequired
namestringyespositional
valueNotionPropertyValueyespositional
pageNotionPageyesoption

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 });
ParameterTypeRequired
valuesRecord<string, NotionPropertyValue>yespositional
databaseNotionDatabaseyesoption

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 });
ParameterTypeRequired
integrationNotionIntegrationyespositional
pageNotionPageyesoption

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 });
ParameterTypeRequired
integrationNotionIntegrationyespositional
pageNotionPageyesoption

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().

FieldPython / RustType
ididstring
discussiondiscussionNotionDiscussion
authorauthorNotionUser | NotionIntegration
texttextstring
createdAtcreated_atstring
deliverydeliveryNotionDelivery | 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);
ParameterTypeRequired
appNotionIntegrationyespositional

Returns NotionDelivery | undefined.

Live: refused with unsupported_in_live: not yet: integrations beside the built-in one aren't built live.

NotionDiscussion#

FieldType
idstring
pageNotionPage
anchorstring | undefined

comments()#

The discussion's comments, oldest first.

const comments = await discussion.comments();

Returns NotionComments.

resolved()#

Whether the discussion is resolved.

const result = await discussion.resolved();

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();

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" });
ParameterPython / RustTypeRequired
fromfrom_ · fromNotionUser | NotionIntegration | stringnoa handle, or a name
timeouttimeoutDurationnodefault 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" });
ParameterPython / RustTypeRequired
fromfrom_ · fromNotionUser | NotionIntegration | stringnoa handle, or a name
timeouttimeoutDurationnodefault 10s
quietForquiet_forDurationnodefault 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().

FieldType
idstring
channel"notion"
titlestring
urlstring

discussions()#

The page's discussions: on the page itself, and on its blocks.

const discussions = await page.discussions();

Returns NotionDiscussions.

markdown()#

The page body as Markdown, once the agent is quiet.

const result = await page.markdown();

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();

Returns NotionBlocks.

property()#

A property's value as a person reads it: text, a number, option names, ids.

const propertyValue = await page.property("…");
ParameterTypeRequired
namestringyespositional

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();

Returns NotionChildPages.

connections()#

The integrations that can see the page: connected to it or to a page above it.

const connections = await page.connections();

Returns NotionConnections.

transcript()#

The page and its discussions as a person reads them.

const transcript = await page.transcript();

Returns NotionTranscript.

NotionDelivery#

Returned by NotionFixture.sendVerification(), NotionIntegration.edit(), NotionIntegration.rename(), NotionUser.editComment().

FieldPython / RustType
ididstring
channelchannel"notion"
appappstring
typetype · r#typestring
entityentity{ type: string; id: string }
payloadpayloadunknown | undefined
attemptsattemptsDeliveryAttempt[]
statusstatus"pending" | "acknowledged" | "failed" | "timed_out" | "unreachable"

refresh()#

Re-read a delivery: its attempts and status.

const updated = await delivery.refresh();

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();

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 });
ParameterPython / RustTypeRequired
badSignaturebad_signaturebooleannooption

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();
ParameterTypeRequired
timeoutDurationnodefault 10s

Returns NotionDelivery. When the time is up, it fails with what it was waiting for.

NotionDatabase#

Returned by NotionFixture.createDatabase().

FieldType
idstring
channel"notion"
titlestring
urlstring

rows()#

The rows of a database, optionally only those whose properties have these values.

const rows = await database.rows();
ParameterTypeRequired
filterRecord<string, NotionPropertyValue>nopositional

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#

FieldType
entriesNotionTranscriptEntry[]
textstring

NotionTranscriptEntry#

FieldType
idstring
authorNotionPrincipal
atstring
textstring
controlsstring[]
editedboolean
depthnumber

NotionPrincipal#

FieldType
idstring
namestring
kind"user" | "app"

NotionRows#

type NotionRows = NotionPage[];

NotionComments#

type NotionComments = NotionComment[];

NotionDeliveries#

type NotionDeliveries = NotionDelivery[];

NotionApiCalls#

type NotionApiCalls = NotionApiCall[];

NotionApiCall#

FieldPython / RustType
ididstring
channelchannel"notion"
operationoperationstring
methodmethodstring
pathpathstring
atatstring
durationMsduration_msnumber
requestrequestunknown | undefined
responseStatusresponse_statusnumber
responseresponseunknown | undefined
errorerrorstring | undefined

This page is generated from the control API's routes by codegen/src/emit/docs.ts: suggest changes there.