-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotion-client.ts
47 lines (41 loc) · 1012 Bytes
/
notion-client.ts
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
export class NotionClient {
secret: string
pageId: string
constructor(secret: string, pageId: string) {
this.secret = secret;
this.pageId = pageId;
}
async save (content: string) {
const body = {
"children": [
{
"object": "block",
"type": "paragraph",
"paragraph": {
"rich_text": [
{
"type": "text",
"text": {
"content": content,
}
}
]
}
}
]
}
const req = new Request(`https://api.notion.com/v1/blocks/${this.pageId}/children`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
"Notion-Version": "2022-02-22",
"Authorization": `Bearer ${this.secret}`
},
body: JSON.stringify(body)
});
const response = await fetch(req);
if (response.status >= 300) {
console.error(`\n${response.text()}\n`);
}
}
}