How to make a request to Notion API using Python

rcmisk
2 min readMay 23, 2024

--

Below is a Python script that uses the requests library to interact with the Notion API and read a specific page. This script automates the process described earlier.

Prerequisites:

  1. Notion Account: Ensure you have a Notion account and a page you want to read.
  2. API Token: Obtain an integration token from Notion by creating an integration at Notion Integrations.
  3. Install the requests library if you haven't already:
pip install requests

Python Script:

import requests

def get_notion_page(page_id, token):
url = f"<https://api.notion.com/v1/pages/{page_id}>"

headers = {
"Authorization": f"Bearer {token}",
"Notion-Version": "2022-06-28",
"Content-Type": "application/json"
}

response = requests.get(url, headers=headers)

if response.status_code == 200:
print("Page details:")
print(response.json())
else:
print(f"Failed to retrieve page. Status code: {response.status_code}")
print(response.text)

if __name__ == "__main__":
# Replace these variables with your actual values
page_id = "your_page_id"
token = "your_integration_token"

get_notion_page(page_id, token)

How to Use:

  1. Replace "your_page_id" with the actual ID of the Notion page you want to read.
  2. Replace "your_integration_token" with your actual Notion integration token.
  3. Run the script.

Running the Script:

Save the script to a file, for example notion_read_page.py, and run it using Python:

python notion_read_page.py

The script will send a GET request to the Notion API and print the details of the specified page.

Written with the help of Gen AI!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

rcmisk
rcmisk

Written by rcmisk

Lover of coding, software development, indie hackers, start-ups, music, guitar, technology, fitness, and learning new things.

No responses yet

Write a response