1

I tried following the documentation from Notion page to use Python API to retrieve a database. However, the API does not return database content. What am I missing in my codes?

import requests

token ='my_token'
databaseId ='my_database_id'
url = f"https://api.notion.com/v1/databases/{databaseId}"
headers = {
    "Authorization": f"{token}",
    "Content-Type": "application/json",
    "Notion-Version": "2022-02-22"
}

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

results:

{"object":"database","id":"85877fac-46c4-4d0a-b161-9802ec0fbe1c","cover":null,"icon":null,"created_time":"2022-05-31T11:18:00.000Z","created_by":{"object":"user","id":"6293a673-9e2b-4675-86b4-6202316058f7"},"last_edited_by":{"object":"user","id":"6293a673-9e2b-4675-86b4-6202316058f7"},"last_edited_time":"2022-05-31T11:21:00.000Z","title":[{"type":"text","text":{"content":"Test DB","link":null},"annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"plain_text":"Test DB","href":null}],"properties":{"Phone":{"id":"kWjl","name":"Phone","type":"rich_text","rich_text":{}},"Address":{"id":"p%3FUh","name":"Address","type":"rich_text","rich_text":{}},"Name":{"id":"title","name":"Name","type":"title","title":{}}},"parent":{"type":"workspace","workspace":true},"url":"https://www.notion.so/85877fac46c44d0ab1619802ec0fbe1c","archived":false}

not same as actual table content: enter image description here

1 Answers1

0

to fix this issue is pretty easy. Notion (for some reason) uses POST to view the database content.

So in your case, instead of using GET, use POST.

Bruno Teixeira
  • 128
  • 1
  • 12