# 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](https://channelstack.dev/docs/platforms/notion).

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`](https://channelstack.dev/docs/reference/api/errors#action-requires), [`cross_workspace_credential`](https://channelstack.dev/docs/reference/api/errors#cross-workspace-credential), [`fake_actor_in_live_world`](https://channelstack.dev/docs/reference/api/errors#fake-actor-in-live-world), [`internal`](https://channelstack.dev/docs/reference/api/errors#internal), [`invalid_argument`](https://channelstack.dev/docs/reference/api/errors#invalid-argument), [`live_misconfigured`](https://channelstack.dev/docs/reference/api/errors#live-misconfigured), [`live_not_allowlisted`](https://channelstack.dev/docs/reference/api/errors#live-not-allowlisted), [`not_found`](https://channelstack.dev/docs/reference/api/errors#not-found), [`session_not_found`](https://channelstack.dev/docs/reference/api/errors#session-not-found), [`unauthorized`](https://channelstack.dev/docs/reference/api/errors#unauthorized), [`unsupported_in_live`](https://channelstack.dev/docs/reference/api/errors#unsupported-in-live): a bad request, a closed session, or live mode refusing or misconfigured.

## NotionFixture

Returned by [`Session.notion()`](https://channelstack.dev/docs/reference/api/client#notion).

| Field    | Python / Rust | Type                |
| -------- | ------------- | ------------------- |
| `app`    | `app`         | `NotionIntegration` |
| `apiUrl` | `api_url`     | `string`            |

### createUser()

Create a person in the workspace.

```ts title="TypeScript"
const user = await notion.createUser({ name: "…" });
```

```python title="Python"
user = await notion.create_user(name="…")
```

```rust title="Rust"
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`](https://channelstack.dev/docs/reference/api/notion#notionuser).

### users()

The people this session created.

```ts title="TypeScript"
const users = await notion.users();
```

```python title="Python"
users = await notion.users()
```

```rust title="Rust"
let users = notion.users().await?;
```

**Returns** [`NotionUsers`](https://channelstack.dev/docs/reference/api/notion#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.

```ts title="TypeScript"
const integration = await notion.createApp({ name: "…" });
```

```python title="Python"
integration = await notion.create_app(name="…")
```

```rust title="Rust"
let integration = notion.create_app().name("…").await?;
```

| Parameter      | Type                 | Required |        |
| -------------- | -------------------- | -------- | ------ |
| `name`         | `string`             | yes      | option |
| `capabilities` | `NotionCapability[]` | no       | option |
| `events`       | `string[]`           | no       | option |

**Returns** [`NotionIntegration`](https://channelstack.dev/docs/reference/api/notion#notionintegration).

**Live:** refused with [`unsupported_in_live`](https://channelstack.dev/docs/reference/api/errors#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.

```ts title="TypeScript"
const integrations = await notion.apps();
```

```python title="Python"
integrations = await notion.apps()
```

```rust title="Rust"
let integrations = notion.apps().await?;
```

**Returns** [`NotionIntegrations`](https://channelstack.dev/docs/reference/api/notion#notionintegrations).

### pages()

The pages this session created, a database's rows included, read again from Notion live, oldest first. Not those in the trash.

```ts title="TypeScript"
const pages = await notion.pages();
```

```python title="Python"
pages = await notion.pages()
```

```rust title="Rust"
let pages = notion.pages().await?;
```

**Returns** [`NotionPages`](https://channelstack.dev/docs/reference/api/notion#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.

```ts title="TypeScript"
const page = await notion.createPage({ title: "…" });
```

```python title="Python"
page = await notion.create_page(title="…")
```

```rust title="Rust"
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`](https://channelstack.dev/docs/reference/api/notion#notionpage).

### createDatabase()

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

```ts title="TypeScript"
const database = await notion.createDatabase({ title: "…", properties });
```

```python title="Python"
database = await notion.create_database(title="…", properties=properties)
```

```rust title="Rust"
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`](https://channelstack.dev/docs/reference/api/notion#notiondatabase).

**Live:** refused with [`unsupported_in_live`](https://channelstack.dev/docs/reference/api/errors#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.

```ts title="TypeScript"
await notion.setContentUpdateDelay(delay);
```

```python title="Python"
await notion.set_content_update_delay(delay)
```

```rust title="Rust"
notion.set_content_update_delay(delay).await?;
```

| Parameter | Type       | Required |            |
| --------- | ---------- | -------- | ---------- |
| `delay`   | `Duration` | yes      | positional |

**Returns** nothing.

**Live:** refused with [`unsupported_in_live`](https://channelstack.dev/docs/reference/api/errors#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.

```ts title="TypeScript"
const delivery = await notion.sendVerification({ app });
```

```python title="Python"
delivery = await notion.send_verification(app=app)
```

```rust title="Rust"
let delivery = notion.send_verification().app(&app).await?;
```

| Parameter | Type                | Required |        |
| --------- | ------------------- | -------- | ------ |
| `app`     | `NotionIntegration` | no       | option |

**Returns** [`NotionDelivery | undefined`](https://channelstack.dev/docs/reference/api/notion#notiondelivery).

**Live:** refused with [`unsupported_in_live`](https://channelstack.dev/docs/reference/api/errors#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.

```ts title="TypeScript"
const deliveries = await notion.deliveries({ type: "…" });
```

```python title="Python"
deliveries = await notion.deliveries(type="…")
```

```rust title="Rust"
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`](https://channelstack.dev/docs/reference/api/notion#notiondeliveries).

**Live:** refused with [`unsupported_in_live`](https://channelstack.dev/docs/reference/api/errors#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`).

```ts title="TypeScript"
const apiCalls = await notion.calls({ operation: "…" });
```

```python title="Python"
api_calls = await notion.calls(operation="…")
```

```rust title="Rust"
let api_calls = notion.calls().operation("…").await?;
```

| Parameter   | Type             | Required |        |
| ----------- | ---------------- | -------- | ------ |
| `operation` | `string`         | no       | option |
| `error`     | `true \| string` | no       | option |

**Returns** [`NotionApiCalls`](https://channelstack.dev/docs/reference/api/notion#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](https://github.com/christian-bromann/channelstack/issues/24)), so for now the call is refused with [`action_requires`](https://channelstack.dev/docs/reference/api/errors#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.

```ts title="TypeScript"
const apiCall = await notion.waitForCall({ operation: "…" });
```

```python title="Python"
api_call = await notion.wait_for_call(operation="…")
```

```rust title="Rust"
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`](https://channelstack.dev/docs/reference/api/notion#notionapicall). When the time is up, it fails with what it was waiting for.

## NotionIntegration

Returned by [`NotionFixture.createApp()`](https://channelstack.dev/docs/reference/api/notion#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.

```ts title="TypeScript"
const comment = await integration.comment("…", { page });
```

```python title="Python"
comment = await integration.comment("…", page=page)
```

```rust title="Rust"
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`](https://channelstack.dev/docs/reference/api/notion#notioncomment).

**Errors** [`object_not_found`](https://channelstack.dev/docs/reference/api/errors#object-not-found), [`restricted_resource`](https://channelstack.dev/docs/reference/api/errors#restricted-resource), [`validation_error`](https://channelstack.dev/docs/reference/api/errors#validation-error).

**Live:** refused with [`unsupported_in_live`](https://channelstack.dev/docs/reference/api/errors#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`.

```ts title="TypeScript"
const comment = await integration.reply("…", { discussion });
```

```python title="Python"
comment = await integration.reply("…", discussion=discussion)
```

```rust title="Rust"
let comment = integration.reply("…").discussion(&discussion).await?;
```

| Parameter    | Type               | Required |            |
| ------------ | ------------------ | -------- | ---------- |
| `text`       | `string`           | yes      | positional |
| `discussion` | `NotionDiscussion` | yes      | option     |

**Returns** [`NotionComment`](https://channelstack.dev/docs/reference/api/notion#notioncomment).

**Errors** [`object_not_found`](https://channelstack.dev/docs/reference/api/errors#object-not-found), [`restricted_resource`](https://channelstack.dev/docs/reference/api/errors#restricted-resource), [`validation_error`](https://channelstack.dev/docs/reference/api/errors#validation-error).

**Live:** refused with [`unsupported_in_live`](https://channelstack.dev/docs/reference/api/errors#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.

```ts title="TypeScript"
const delivery = await integration.edit(change, { page });
```

```python title="Python"
delivery = await integration.edit(change, page=page)
```

```rust title="Rust"
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`](https://channelstack.dev/docs/reference/api/notion#notiondelivery).

**Errors** [`object_not_found`](https://channelstack.dev/docs/reference/api/errors#object-not-found), [`restricted_resource`](https://channelstack.dev/docs/reference/api/errors#restricted-resource), [`validation_error`](https://channelstack.dev/docs/reference/api/errors#validation-error).

**Live:** refused with [`unsupported_in_live`](https://channelstack.dev/docs/reference/api/errors#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`.

```ts title="TypeScript"
const delivery = await integration.rename("…", { page });
```

```python title="Python"
delivery = await integration.rename("…", page=page)
```

```rust title="Rust"
let delivery = integration.rename("…").page(&page).await?;
```

| Parameter | Type         | Required |            |
| --------- | ------------ | -------- | ---------- |
| `title`   | `string`     | yes      | positional |
| `page`    | `NotionPage` | yes      | option     |

**Returns** [`NotionDelivery | undefined`](https://channelstack.dev/docs/reference/api/notion#notiondelivery).

**Errors** [`object_not_found`](https://channelstack.dev/docs/reference/api/errors#object-not-found), [`restricted_resource`](https://channelstack.dev/docs/reference/api/errors#restricted-resource), [`validation_error`](https://channelstack.dev/docs/reference/api/errors#validation-error).

**Live:** refused with [`unsupported_in_live`](https://channelstack.dev/docs/reference/api/errors#unsupported-in-live): not yet: integrations beside the built-in one aren't built live.

## NotionUser

Returned by [`NotionFixture.createUser()`](https://channelstack.dev/docs/reference/api/notion#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.

```ts title="TypeScript"
const comment = await user.comment("…", { page });
```

```python title="Python"
comment = await user.comment("…", page=page)
```

```rust title="Rust"
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`](https://channelstack.dev/docs/reference/api/notion#notioncomment).

### reply()

Reply in a discussion. Sends `comment.created`.

```ts title="TypeScript"
const comment = await user.reply("…", { discussion });
```

```python title="Python"
comment = await user.reply("…", discussion=discussion)
```

```rust title="Rust"
let comment = user.reply("…").discussion(&discussion).await?;
```

| Parameter    | Type               | Required |            |
| ------------ | ------------------ | -------- | ---------- |
| `text`       | `string`           | yes      | positional |
| `discussion` | `NotionDiscussion` | yes      | option     |

**Returns** [`NotionComment`](https://channelstack.dev/docs/reference/api/notion#notioncomment).

### editComment()

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

```ts title="TypeScript"
const delivery = await user.editComment("…", { comment });
```

```python title="Python"
delivery = await user.edit_comment("…", comment=comment)
```

```rust title="Rust"
let delivery = user.edit_comment("…").comment(&comment).await?;
```

| Parameter | Type            | Required |            |
| --------- | --------------- | -------- | ---------- |
| `text`    | `string`        | yes      | positional |
| `comment` | `NotionComment` | yes      | option     |

**Returns** [`NotionDelivery | undefined`](https://channelstack.dev/docs/reference/api/notion#notiondelivery).

**Errors** [`forbidden`](https://channelstack.dev/docs/reference/api/errors#forbidden).

### deleteComment()

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

```ts title="TypeScript"
const delivery = await user.deleteComment({ comment });
```

```python title="Python"
delivery = await user.delete_comment(comment=comment)
```

```rust title="Rust"
let delivery = user.delete_comment().comment(&comment).await?;
```

| Parameter | Type            | Required |        |
| --------- | --------------- | -------- | ------ |
| `comment` | `NotionComment` | yes      | option |

**Returns** [`NotionDelivery | undefined`](https://channelstack.dev/docs/reference/api/notion#notiondelivery).

**Errors** [`forbidden`](https://channelstack.dev/docs/reference/api/errors#forbidden).

### resolve()

Resolve a discussion. Notion sends no event for it, and the API no longer lists its comments.

```ts title="TypeScript"
const delivery = await user.resolve({ discussion });
```

```python title="Python"
delivery = await user.resolve(discussion=discussion)
```

```rust title="Rust"
let delivery = user.resolve().discussion(&discussion).await?;
```

| Parameter    | Type               | Required |        |
| ------------ | ------------------ | -------- | ------ |
| `discussion` | `NotionDiscussion` | yes      | option |

**Returns** [`NotionDelivery | undefined`](https://channelstack.dev/docs/reference/api/notion#notiondelivery).

**Live:** refused with [`unsupported_in_live`](https://channelstack.dev/docs/reference/api/errors#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.

```ts title="TypeScript"
const delivery = await user.reopen({ discussion });
```

```python title="Python"
delivery = await user.reopen(discussion=discussion)
```

```rust title="Rust"
let delivery = user.reopen().discussion(&discussion).await?;
```

| Parameter    | Type               | Required |        |
| ------------ | ------------------ | -------- | ------ |
| `discussion` | `NotionDiscussion` | yes      | option |

**Returns** [`NotionDelivery | undefined`](https://channelstack.dev/docs/reference/api/notion#notiondelivery).

**Live:** refused with [`unsupported_in_live`](https://channelstack.dev/docs/reference/api/errors#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.

```ts title="TypeScript"
const result = await user.createPage(page);
```

```python title="Python"
result = await user.create_page(page)
```

```rust title="Rust"
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`](https://channelstack.dev/docs/reference/api/notion#notionpage).

### edit()

Edit a page's body: append, or replace it. Sends one `page.content_updated` once Notion's batching delay is over.

```ts title="TypeScript"
const delivery = await user.edit(change, { page });
```

```python title="Python"
delivery = await user.edit(change, page=page)
```

```rust title="Rust"
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`](https://channelstack.dev/docs/reference/api/notion#notiondelivery).

### rename()

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

```ts title="TypeScript"
const delivery = await user.rename("…", { page });
```

```python title="Python"
delivery = await user.rename("…", page=page)
```

```rust title="Rust"
let delivery = user.rename("…").page(&page).await?;
```

| Parameter | Type         | Required |            |
| --------- | ------------ | -------- | ---------- |
| `title`   | `string`     | yes      | positional |
| `page`    | `NotionPage` | yes      | option     |

**Returns** [`NotionDelivery | undefined`](https://channelstack.dev/docs/reference/api/notion#notiondelivery).

### 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.

```ts title="TypeScript"
const delivery = await user.mention(integration, { page });
```

```python title="Python"
delivery = await user.mention(integration, page=page)
```

```rust title="Rust"
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`](https://channelstack.dev/docs/reference/api/notion#notiondelivery).

### setProperty()

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

```ts title="TypeScript"
const delivery = await user.setProperty("…", value, { page });
```

```python title="Python"
delivery = await user.set_property("…", value, page=page)
```

```rust title="Rust"
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`](https://channelstack.dev/docs/reference/api/notion#notiondelivery).

**Live:** refused with [`unsupported_in_live`](https://channelstack.dev/docs/reference/api/errors#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.

```ts title="TypeScript"
const page = await user.addRow(values, { database });
```

```python title="Python"
page = await user.add_row(values, database=database)
```

```rust title="Rust"
let page = user.add_row(values).database(&database).await?;
```

| Parameter  | Type                                  | Required |            |
| ---------- | ------------------------------------- | -------- | ---------- |
| `values`   | `Record<string, NotionPropertyValue>` | yes      | positional |
| `database` | `NotionDatabase`                      | yes      | option     |

**Returns** [`NotionPage`](https://channelstack.dev/docs/reference/api/notion#notionpage).

**Live:** refused with [`unsupported_in_live`](https://channelstack.dev/docs/reference/api/errors#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.

```ts title="TypeScript"
await user.connect(integration, { page });
```

```python title="Python"
await user.connect(integration, page=page)
```

```rust title="Rust"
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](https://github.com/christian-bromann/channelstack/issues/47)), so for now the call is refused with [`action_requires`](https://channelstack.dev/docs/reference/api/errors#action-requires) and the test is skipped.

### disconnect()

Remove the integration's connection from a page.

```ts title="TypeScript"
await user.disconnect(integration, { page });
```

```python title="Python"
await user.disconnect(integration, page=page)
```

```rust title="Rust"
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](https://github.com/christian-bromann/channelstack/issues/47)), so for now the call is refused with [`action_requires`](https://channelstack.dev/docs/reference/api/errors#action-requires) and the test is skipped.

## NotionComment

Returned by [`NotionIntegration.comment()`](https://channelstack.dev/docs/reference/api/notion#comment), [`NotionIntegration.reply()`](https://channelstack.dev/docs/reference/api/notion#reply), [`NotionUser.comment()`](https://channelstack.dev/docs/reference/api/notion#comment-1), [`NotionUser.reply()`](https://channelstack.dev/docs/reference/api/notion#reply-1).

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

```ts title="TypeScript"
const delivery = await comment.deliveryFor(app);
```

```python title="Python"
delivery = await comment.delivery_for(app)
```

```rust title="Rust"
let delivery = comment.delivery_for(&app).await?;
```

| Parameter | Type                | Required |            |
| --------- | ------------------- | -------- | ---------- |
| `app`     | `NotionIntegration` | yes      | positional |

**Returns** [`NotionDelivery | undefined`](https://channelstack.dev/docs/reference/api/notion#notiondelivery).

**Live:** refused with [`unsupported_in_live`](https://channelstack.dev/docs/reference/api/errors#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.

```ts title="TypeScript"
const comments = await discussion.comments();
```

```python title="Python"
comments = await discussion.comments()
```

```rust title="Rust"
let comments = discussion.comments().await?;
```

**Returns** [`NotionComments`](https://channelstack.dev/docs/reference/api/notion#notioncomments).

### resolved()

Whether the discussion is resolved.

```ts title="TypeScript"
const result = await discussion.resolved();
```

```python title="Python"
result = await discussion.resolved()
```

```rust title="Rust"
let result = discussion.resolved().await?;
```

**Returns** `boolean`.

**Live:** refused with [`unsupported_in_live`](https://channelstack.dev/docs/reference/api/errors#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.

```ts title="TypeScript"
const transcript = await discussion.transcript();
```

```python title="Python"
transcript = await discussion.transcript()
```

```rust title="Rust"
let transcript = discussion.transcript().await?;
```

**Returns** [`NotionTranscript`](https://channelstack.dev/docs/reference/api/notion#notiontranscript).

### waitForComment()

Waits for the next comment after the last one this handle returned: it polls `comments()` and never sleeps longer than it must.

```ts title="TypeScript"
const comment = await discussion.waitForComment({ from: "my-agent" });
```

```python title="Python"
comment = await discussion.wait_for_comment(from_="my-agent")
```

```rust title="Rust"
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`](https://channelstack.dev/docs/reference/api/notion#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.

```ts title="TypeScript"
const comment = await discussion.latestComment({ from: "my-agent" });
```

```python title="Python"
comment = await discussion.latest_comment(from_="my-agent")
```

```rust title="Rust"
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`](https://channelstack.dev/docs/reference/api/notion#notioncomment). When the time is up, it fails with what it was waiting for.

## NotionPage

Returned by [`NotionFixture.createPage()`](https://channelstack.dev/docs/reference/api/notion#createpage), [`NotionUser.createPage()`](https://channelstack.dev/docs/reference/api/notion#createpage-1), [`NotionUser.addRow()`](https://channelstack.dev/docs/reference/api/notion#addrow).

| Field     | Type       |
| --------- | ---------- |
| `id`      | `string`   |
| `channel` | `"notion"` |
| `title`   | `string`   |
| `url`     | `string`   |

### discussions()

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

```ts title="TypeScript"
const discussions = await page.discussions();
```

```python title="Python"
discussions = await page.discussions()
```

```rust title="Rust"
let discussions = page.discussions().await?;
```

**Returns** [`NotionDiscussions`](https://channelstack.dev/docs/reference/api/notion#notiondiscussions).

### markdown()

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

```ts title="TypeScript"
const result = await page.markdown();
```

```python title="Python"
result = await page.markdown()
```

```rust title="Rust"
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`.

```ts title="TypeScript"
const blocks = await page.blocks();
```

```python title="Python"
blocks = await page.blocks()
```

```rust title="Rust"
let blocks = page.blocks().await?;
```

**Returns** [`NotionBlocks`](https://channelstack.dev/docs/reference/api/notion#notionblocks).

### property()

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

```ts title="TypeScript"
const propertyValue = await page.property("…");
```

```python title="Python"
property_value = await page.property("…")
```

```rust title="Rust"
let property_value = page.property("…").await?;
```

| Parameter | Type     | Required |            |
| --------- | -------- | -------- | ---------- |
| `name`    | `string` | yes      | positional |

**Returns** [`NotionPropertyValue`](https://channelstack.dev/docs/reference/api/notion#notionpropertyvalue).

**Live:** refused with [`unsupported_in_live`](https://channelstack.dev/docs/reference/api/errors#unsupported-in-live): not yet: Notion databases, rows and properties aren't built live.

### children()

The pages directly under this page.

```ts title="TypeScript"
const childPages = await page.children();
```

```python title="Python"
child_pages = await page.children()
```

```rust title="Rust"
let child_pages = page.children().await?;
```

**Returns** [`NotionChildPages`](https://channelstack.dev/docs/reference/api/notion#notionchildpages).

### connections()

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

```ts title="TypeScript"
const connections = await page.connections();
```

```python title="Python"
connections = await page.connections()
```

```rust title="Rust"
let connections = page.connections().await?;
```

**Returns** [`NotionConnections`](https://channelstack.dev/docs/reference/api/notion#notionconnections).

### transcript()

The page and its discussions as a person reads them.

```ts title="TypeScript"
const transcript = await page.transcript();
```

```python title="Python"
transcript = await page.transcript()
```

```rust title="Rust"
let transcript = page.transcript().await?;
```

**Returns** [`NotionTranscript`](https://channelstack.dev/docs/reference/api/notion#notiontranscript).

## NotionDelivery

Returned by [`NotionFixture.sendVerification()`](https://channelstack.dev/docs/reference/api/notion#sendverification), [`NotionIntegration.edit()`](https://channelstack.dev/docs/reference/api/notion#edit), [`NotionIntegration.rename()`](https://channelstack.dev/docs/reference/api/notion#rename), [`NotionUser.editComment()`](https://channelstack.dev/docs/reference/api/notion#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.

```ts title="TypeScript"
const updated = await delivery.refresh();
```

```python title="Python"
updated = await delivery.refresh()
```

```rust title="Rust"
let updated = delivery.refresh().await?;
```

**Returns** [`NotionDelivery`](https://channelstack.dev/docs/reference/api/notion#notiondelivery).

**Live:** refused with [`unsupported_in_live`](https://channelstack.dev/docs/reference/api/errors#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.

```ts title="TypeScript"
const deliveryAttempt = await delivery.redeliver();
```

```python title="Python"
delivery_attempt = await delivery.redeliver()
```

```rust title="Rust"
let delivery_attempt = delivery.redeliver().await?;
```

**Returns** [`DeliveryAttempt`](https://channelstack.dev/docs/reference/api/client#deliveryattempt).

**Live:** refused with [`unsupported_in_live`](https://channelstack.dev/docs/reference/api/errors#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.

```ts title="TypeScript"
const deliveryAttempt = await delivery.resend({ badSignature });
```

```python title="Python"
delivery_attempt = await delivery.resend(bad_signature=bad_signature)
```

```rust title="Rust"
let delivery_attempt = delivery.resend().bad_signature(bad_signature).await?;
```

| Parameter      | Python / Rust   | Type      | Required |        |
| -------------- | --------------- | --------- | -------- | ------ |
| `badSignature` | `bad_signature` | `boolean` | no       | option |

**Returns** [`DeliveryAttempt`](https://channelstack.dev/docs/reference/api/client#deliveryattempt).

**Live:** refused with [`unsupported_in_live`](https://channelstack.dev/docs/reference/api/errors#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.

```ts title="TypeScript"
const updated = await delivery.settled();
```

```python title="Python"
updated = await delivery.settled()
```

```rust title="Rust"
let updated = delivery.settled().await?;
```

| Parameter | Type       | Required |             |
| --------- | ---------- | -------- | ----------- |
| `timeout` | `Duration` | no       | default 10s |

**Returns** [`NotionDelivery`](https://channelstack.dev/docs/reference/api/notion#notiondelivery). When the time is up, it fails with what it was waiting for.

## NotionDatabase

Returned by [`NotionFixture.createDatabase()`](https://channelstack.dev/docs/reference/api/notion#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.

```ts title="TypeScript"
const rows = await database.rows();
```

```python title="Python"
rows = await database.rows()
```

```rust title="Rust"
let rows = database.rows().await?;
```

| Parameter | Type                                  | Required |            |
| --------- | ------------------------------------- | -------- | ---------- |
| `filter`  | `Record<string, NotionPropertyValue>` | no       | positional |

**Returns** [`NotionRows`](https://channelstack.dev/docs/reference/api/notion#notionrows).

**Live:** refused with [`unsupported_in_live`](https://channelstack.dev/docs/reference/api/errors#unsupported-in-live): not yet: Notion databases, rows and properties aren't built live.

## Types

Plain values the handles return and take.

### NotionCapability

```ts
type NotionCapability = "read_content" | "update_content" | "insert_content" | "read_comments" | "insert_comments" | "read_user_info";
```

### NotionIntegrations

```ts
type NotionIntegrations = NotionIntegration[];
```

### NotionUsers

```ts
type NotionUsers = NotionUser[];
```

### NotionPages

```ts
type NotionPages = NotionPage[];
```

### NotionPropertySchema

```ts
type NotionPropertySchema = "title" | "rich_text" | "number" | "checkbox" | "date" | "people" | "url" | "email" | { select: string[] } | { multi_select: string[] } | { status: string[] } | { relation: NotionDatabase };
```

### NotionPropertyValue

```ts
type NotionPropertyValue = string | number | boolean | string[] | { start: string; end?: string } | undefined;
```

### NotionDiscussions

```ts
type NotionDiscussions = NotionDiscussion[];
```

### NotionBlocks

```ts
type NotionBlocks = unknown[];
```

### NotionChildPages

```ts
type NotionChildPages = NotionPage[];
```

### NotionConnections

```ts
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

```ts
type NotionRows = NotionPage[];
```

### NotionComments

```ts
type NotionComments = NotionComment[];
```

### NotionDeliveries

```ts
type NotionDeliveries = NotionDelivery[];
```

### NotionApiCalls

```ts
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`  |
