-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackup.ts
More file actions
60 lines (46 loc) · 1.59 KB
/
Backup.ts
File metadata and controls
60 lines (46 loc) · 1.59 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
import dotenv from "dotenv";
dotenv.config();
import * as fs from "fs";
import { Client, LogLevel } from "@notionhq/client";
import { DatabasesQueryParameters } from "@notionhq/client/build/src/api-endpoints";
const databaseID = "dae968ec2e6a4e15aec83a25c790b1a3";
const main = async () => {
const notion = new Client({
"auth": process.env.NOTION_TOKEN,
"logLevel": LogLevel.DEBUG,
});
const tasksDatabase = await notion.databases.retrieve({"database_id": databaseID});
console.log(tasksDatabase);
fs.writeFileSync("Database.json", JSON.stringify(tasksDatabase, null, 2));
let hasMore = true;
let nextCursor : string | null = null;
const tasks = [];
while (hasMore){
const request : DatabasesQueryParameters = {
"database_id": databaseID,
"sorts": [
{
"property": "List",
"direction": "ascending",
},
{
"property": "Priority",
"direction": "ascending",
},
{
"property": "Start Date",
"direction": "ascending",
}
],
};
if (nextCursor !== null)
request.start_cursor = nextCursor;
const response = await notion.databases.query(request);
tasks.push(...response.results);
hasMore = response.has_more;
nextCursor = response.next_cursor;
}
console.log(tasks);
fs.writeFileSync("Tasks.json", JSON.stringify(tasks, null, 2));
};
main();