# Notion connector (https://docs.ctxpipe.ai/docs/connections/source-connectors/notion)

The **Notion connector** mirrors selected pages and databases into a
[Workspace](/docs/workspaces) repository. ctxpipe reads Notion content. It does
not create or change it.

On a self-hosted deployment, the operator registers a Notion OAuth app and its
webhook first. See [Self-host Notion](/docs/self-hosting/notion).

## What is mirrored

A page syncs with all its child pages, and with the child pages that you add later. A
database syncs with all its rows. The mirror includes:

* pages as Markdown, with headings, lists, tasks, quotes, and code. Links to
  other mirrored pages become relative links;
* each database as an index page, a `table.csv` snapshot, and one Markdown file
  for each row;
* images, files, video, audio, and PDFs, copied into git.

Page comments are not mirrored.

<Callout title="Notion sharing sets what ctxpipe can read">
  ctxpipe can list only the pages and databases that are shared with the
  ctxpipe integration. Share them in the authorization popup, or later in
  Notion. Each person who can read the Workspace repository can read the
  mirrored files.
</Callout>

## Connect Notion

Follow [Add a tool to a Workspace](/docs/connections#add-a-tool-to-a-workspace).
For Notion:

1. On **Connectors**, select **Add connection**, then select **Connect** on the
   **Notion** row. Authorize your Notion workspace, and share the pages and databases that ctxpipe can
   read.
2. In **Add to Workspaces**, select the Workspaces, then search for the pages
   and databases. Keep the selection narrow when the Notion workspace has
   private notes.
3. Merge the pull request that adds `sources/notion/<name>.md`.

## Source file

```markdown
---
provider: notion
connection: con_example
pages:
  - id: 1f2e3d4c-5b6a-4978-8695-a4b3c2d1e0f9
    title: Engineering handbook
databases:
  - id: 0a1b2c3d-4e5f-4061-8728-394a5b6c7d8e
    title: Runbooks
---
```

## Files in the repository

* Pages: `notion/pages/<slug>--<id>/index.md`, with child pages inside the
  folder of their parent.
* Databases: `notion/databases/<slug>--<id>/index.md`, `table.csv`, and
  `rows/<slug>--<id>/index.md`.

The paths use stable Notion ids, so a renamed page does not make a second copy.
Assets are in an `assets/` folder next to their page. Each asset can be up to
25 MiB, and each page or row up to 100 MiB in total. A file that is too large or
not safe stays a link to Notion. ctxpipe never writes the download URLs
of Notion to git, because they expire.

When a page changes in Notion, ctxpipe syncs the whole page tree or database
that holds it again.

## Check the setup

1. The Notion workspace shows on **Connectors**.
2. After the merge, the Workspace repository has files under `notion/`.
3. When you change a mirrored page in Notion, the file of that page changes. This
   step tests the Notion webhook.

## Troubleshooting

* **No pages or databases show.** Share them with the ctxpipe integration in
  Notion, then search again. ctxpipe lists only the pages and databases that
  you share with the integration. A page that you stop sharing leaves the
  list.

For other problems, see [Troubleshooting](/docs/connections#troubleshooting).
