Notion
Interact with your Notion workspace with low code drivers on top of the official API.
This driver is in beta. Contact us on Slack on #04_question channel if you need help.
If you are not familiar with Notion, check out their website. It's pretty amazing all-in-workspace.
Find below is their website👇
Notion – The all-in-one workspace for your notes, tasks, wikis, and databases.
Notion
Login link
Before anything, you have to connect to your account in Notion, create your integration and make sure it has access to your page or your database.

Step 1: Create an integration.

  • Click the "+ New integration" button.
  • Give your integration a name - I chose "Vacation Planner".
  • Select the workspace where you want to install this integration.
  • Click "Submit" to create the integration.
  • Copy the "Internal Integration Token" on the next page and save it somewhere secure, e.g. a password manager.

Step 2: Share a database with your integration

Integrations don't have access to any pages (or databases) in the workspace at first. A user must share specific pages with an integration in order for those pages to be accessed using the API. This helps keep you and your team's information in Notion secure.
Start from a new or existing page in your workspace. Insert a new database by typing /table and selecting a full page table. Give it a title. I've called mine "Weekend getaway destinations". Click on the Share button and use the selector to find your integration by its name, then click Invite.

Connect

1
from naas_drivers import notion
2
3
token = "*********"
4
notion.connect(token)
Copied!

Get database

1
from naas_drivers import notion
2
3
token = "*********"
4
database_url = "https://www.notion.so/naas-official/8910d64de001479c8494fbecbf52b525?v=4911d8baa8a5494a86f6215a6b0c95fe"
5
database = notion.connect(token).database.get(database_url)
6
database
Copied!

Create a blank page inside a database

1
from naas_drivers import notion
2
3
token = "*********"
4
database_url = "https://www.notion.so/naas-official/8910d64de001479c8494fbecbf52b525?v=4911d8baa8a5494a86f6215a6b0c95fe"
5
6
page = notion.connect(token).page.create(database_id=database_url, title="Page title")
7
page
Copied!

Create a blank page inside a page

This feature is yet supported. Contact us on Slack on #04_question channel if you need it.
1
from naas_drivers import notion
2
3
token = "*********"
4
page_url = "https://www.notion.so/naas-official/8910d64de001479c8494fbecbf52b525?v=4911d8baa8a5494a86f6215a6b0c95fe"
5
6
page = notion.connect(token).page.create(page_id=page_url, title="Page title")
7
page
Copied!

Update a page inside a database with properties

Properties are associated with the database. If you put a page type that is not currently present, it will create it.
The types of properties available are listed below (".type")
The first paramater into the parenthesis is the name of the field, the second is the value to update.
1
from naas_drivers import notion
2
3
token = "*********"
4
page_url = "https://www.notion.so/naas-official/Daily-meeting-04-10-2021-2187d1d0f228491c8ef32de65dea8b1c"
5
6
page = notion.connect(token).page.get(page_url)
7
8
page.title("Name","Page title")
9
page.rich_text("Text","Ceci est toto")
10
page.number("Number", 42)
11
page.select("Select","Value1")
12
page.multi_select("Muti Select",["Value1","Value2","Value3"])
13
page.date("Date","2021-10-03T17:01:26") #Follow ISO 8601 format
14
page.people("People", ["d40e767c-d7af-4b18-a86d-55c61f1e39a4"]) #list of ID of users
15
page.checkbox("Checkbox", True)
16
page.email("Email","[email protected]")
17
page.phone_number("Phone number","+33 6 21 83 11 12")
18
19
page.update()
20
21
22
#Not yet supported
23
#page.url("URL","www.naas.ai")
24
#page.properties.formula()
25
#page.properties.relation()
26
#page.properties.rollup()
27
#page.properties.files()
Copied!

Add "Updated at" property

Know when the page has last been updated.
1
database.add_property("Updated at","last_edited_time")
2
database.update()
Copied!

Create Block inside a page

1
from naas_drivers import notion
2
3
token = "*********"
4
page_url = "https://www.notion.so/naas-official/Daily-meeting-04-10-2021-2187d1d0f228491c8ef32de65dea8b1c"
5
6
page = notion.connect(token).page.get(page_url)
7
8
page.heading_1("Heading 1")
9
page.heading_2("Heading 2")
10
page.heading_3("Heading 3")
11
page.paragraph("Paragraph")
12
page.numbered_list_item("This is first")
13
page.to_do("Need this to be done")
14
page.embed("https://docs.google.com/spreadsheets/*************")
15
page.video("https://www.youtube.com/watch?v=8AsMAc4VFJs")
16
page.image("https://landen.imgix.net/jtci2pxwjczr/assets/5ice39g4.png")
17
page.code("pip install naas")
18
page.equation("e=mc2")
19
20
#The order in parathesis will define the order of the block creation.
21
page.update()
22
23
#Not yet supported
24
#page.pdf("https://bitcoin.org/bitcoin.pdf") #not working
25
#page.bookmark("https://en.wikipedia.org/wiki/Project_Jupyter") #do create a bookmark but do not add the link
26
#page.toggle("Oh") #Should be getting a child block
27
#page.child_page()
28
#page.child_database()
29
#page.properties.formula()
30
#page.properties.relation()
31
#page.properties.rollup()
32
#page.properties.files()
Copied!
The embed blocks are not yet supported. See changelog.

Get the list of users

1
from naas_drivers import notion
2
3
token = "*********"
4
5
users = notion.connect(token).users.list()
6
users
Copied!
Discover more usage of the API with Notion official documentation:
Start building with the Notion API
Notion API
Last modified 6mo ago