Skip to content

Notion

The library provides a collection of useful utilities to manage your Notion workspace.

Setting up Connection

The main goal of this application is to use the Official Notion API whereever possible. Unfortunately, is still in beta and misses various functions required for task automation.

Therefore, we currently use both API's, though if you do not want to use the Unofficial API it is optional. All functions using the Unofficial API are marked as such and should in this case be avoided.

Official API

Configuring the Official API is quite straightforward.

  1. Create an internal integration for the desired workspace and find the API token.
  2. Give access to your integration for the desired pages within your workspace.

Update the configuration with the obtained credentials:

...
connections:
  ...
  notion:
    token: 'your api token goes here'

→ Learn more about authorization.

→ Managing intergrations.

Unofficial API

Configuring Unofficial Notion API requires obtain the token_v2 value by inspecting your browser cookies on a logged-in (non-guest) session on Notion.so.

Update the configuration with the obtained credentials:

...
connections:
  ...
  notion_unofficial:
    token_v2: 'your api token goes here'

Duplicating Pages

It is possible to duplicate a page from the CLI which is useful for setup automation. This can be done by specifying source page url and target parent page url.

Example:

notionsci notion duplicate <source page url or id> <parent page url of id>

Usage: python -m notionsci notion duplicate [OPTIONS] SOURCE PARENT

  Duplicates given SOURCE page into a PARENT page as a child page.

  SOURCE: Source page ID or url PARENT: Destination parent page ID or url

  Requires unofficial notion api

Options:
  --target_id TEXT  Unique ID for the resulting page
  --help            Show this message and exit.

Downloading Markdown Pages

It is possible to download pages as markdown files.
Note: that currently not all blocks are supported due to Notion api limitations

Example:

notionsci notion download-md <source page url or id> -o ./test.md

Usage: python -m notionsci notion download-md [OPTIONS] PAGE

  Downloads given PAGE as a markdown file as given output file or folder

  Note: that currently not all blocks are supported due to Notion api
  limitations

  :param page: :param output: :return:

Options:
  -o, --output TEXT  Output directory or file
  --help             Show this message and exit.

Cleaning Workspace Trash

When you or the connection delete the page, it is archived and placed in the trash. Cleaning it manually is slow, therefore the following command can be used te permanently delete all pages in the trash bin of the given workspace.

Example:

notionsci notion clear-trash <workspace name>

Usage: python -m notionsci notion clear-trash [OPTIONS] [WORKSPACE]

  Permanently deleted all _deleted_/_trashed_ pages in a workspace

  WORKSPACE: Workspace id or name to clean. If not specified a selection
  dialog is prompted.

  Requires unofficial notion api

Options:
  --help  Show this message and exit.
Back to top