-
Notifications
You must be signed in to change notification settings - Fork 1
/
integration_notion_api.py
28 lines (25 loc) · 1.04 KB
/
integration_notion_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import requests
class NotionAPI:
def __init__(self, token, version="2022-02-22"):
self.token = token
self.version = version
self.headers = {
"Authorization": f"Bearer {self.token}",
"Content-Type": "application/json",
"Notion-Version": self.version
}
self.notion_api_url = "https://api.notion.com/v1/"
def create_database(self, data):
response = requests.post(self.notion_api_url + "databases", headers=self.headers, json=data)
if response.status_code == 200:
return response.json()
else:
print(f"Request failed with status {response.status_code}: {response.text}")
return None
def create_page(self,data):
response = requests.post(self.notion_api_url + "pages", headers=self.headers, json=data)
if response.status_code == 200:
return response.json()
else:
print(f"Request failed with status {response.status_code}: {response.text}")
return None