Links
Comment on page

Delete all pages from database

Tags: #notion #productivity #naas_drivers #operations #snippet #database
Author: Florent Ravenel​
Last update: 2023-04-12 (Created: 2023-01-24)
Description: This notebook deletes all page from a Notion database.

Input

Import libraries

from naas_drivers import notion

Setup Notion

# Enter Token API
NOTION_TOKEN = "ENTER_YOUR_NOTION_TOKEN_HERE" # EXAMPLE: "secret_xxxxxxxxxxxxxxxxxx"
​
# Enter Page URL
DATABASE_URL = "ENTER_YOUR_DATABASE_URL_HERE" # EXAMPLE: "https://www.notion.so/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

Model

Get page

def delete_all_pages(database_url, token):
# Get pages
database_id = database_url.split("/")[-1].split("?v=")[0]
pages = notion.connect(token).database.query(database_id, query={})
for page in pages:
notion.connect(token).blocks.delete(page.id)
print(f"{page.id} removed from database")

Output

Delete all pages from database

delete_all_pages(DATABASE_URL, NOTION_TOKEN)