Links
Comment on page

Update pages from database

Tags: #notion #productivity #naas_drivers #operations #snippet
Author: Maxime Jublou​
Last update: 2023-04-12 (Created: 2022-02-07)
Description: This notebook allows users to easily update Notion pages with data from a database.

Input

Import library

from naas_drivers import notion

Setup Notion

# Enter Token API
notion_token = "*****"
​
# Enter Database URL
database_url = "https://www.notion.so/********"

Model

Get pages from Notion DB

database_id = database_url.split("/")[-1].split("?v=")[0]
pages = notion.connect(notion_token).database.query(database_id, query={})
print("📊 Pages in Notion DB:", len(pages))

Output

Update pages

for page in pages:
print(page)
# page.title("Name","Page updated")
# page.rich_text("Text","Ceci est toto")
# page.number("Number", 42)
# page.select("Select","Value3")
# page.multi_select("Muti Select",["Value1","Value2","Value3"])
# page.date("Date","2021-10-03T17:01:26") #Follow ISO 8601 format
# page.people("People", ["6e3bab71-beeb-484b-af99-ea30fdef4773"]) #list of ID of users
# page.checkbox("Checkbox", False)
# page.email("Email","[email protected]")
page.update()
print(f"✅ Page updated in Notion.")