This repository has been archived by the owner on Jun 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ClickUpAPIUtils.js
140 lines (132 loc) · 3.71 KB
/
ClickUpAPIUtils.js
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
const fetch = require("node-fetch");
const config = require("./config");
module.exports = {
/**
* fetches all lists
* @param {string} folder_id
*/
async getLists(folder_id) {
return await fetch(`https://api.clickup.com/api/v2/folder/${folder_id}/list`, {
method: "GET",
headers: {
Authorization: config.CLICKUP_TOKEN,
"Content-Type": "application/json",
},
}).then(async (res) => {
const json = await res.json();
return json.lists;
});
},
/**
* fetches a list by id
* @param {string} list_id
*/
async getList(list_id) {
return await fetch(`https://api.clickup.com/api/v2/list/${list_id}`, {
method: "GET",
headers: {
Authorization: config.CLICKUP_TOKEN,
"Content-Type": "application/json",
},
}).then((res) => res.json());
},
/**
* Fetches all folders
*/
async getFolders() {
return await fetch(
`https://api.clickup.com/api/v2/space/${config.SPACE_ID}/folder?archived=false`,
{
method: "GET",
headers: {
Authorization: config.CLICKUP_TOKEN,
"Content-Type": "application/json",
},
}
).then(async (res) => {
const json = await res.json();
return json.folders;
});
},
/**
* Gets a folder by id
* @param {string} id
*/
async getFolder(folder_id) {
return await fetch(`https://api.clickup.com/api/v2/folder/${folder_id}`, {
method: "GET",
headers: {
Authorization: config.CLICKUP_TOKEN,
"Content-Type": "application/json",
},
}).then((res) => res.json());
},
/**
* Fetchs all tasks from a list
* @param {Number} list_id id of list
* @param {boolean} archived default false
* @param {Number} page page to fetch - default 0
* @param {string} order_by orders by field - default created, options: id, created, updated, due_date
* @param {boolean} reverse default false
* @param {boolean} subtasks default false
*/
async getTasks(
list_id,
archived = false,
page = 0,
order_by = "created",
reverse = false,
subtasks = false
) {
return await fetch(
`https://api.clickup.com/api/v2/list/${list_id}/task?archived=${archived}&page=${page}&order_by=${order_by}&reverse=${reverse}&subtasks=${subtasks}`,
{
method: "GET",
headers: {
Authorization: config.CLICKUP_TOKEN,
"Content-Type": "application/json",
},
}
).then(async (res) => {
const json = await res.json();
return json.tasks;
});
},
/**
* gets a task by id
* @param {string} task_id
*/
async getTask(task_id) {
return await fetch(`https://api.clickup.com/api/v2/task/${task_id}`, {
method: "GET",
headers: {
Authorization: config.CLICKUP_TOKEN,
"Content-Type": "application/json",
},
}).then((res) => res.json());
},
async createTask(list_id, name, content) {
const body = JSON.stringify({
name,
text_content: content,
notify_all: true,
});
return await fetch(`https://api.clickup.com/api/v2/list/${list_id}/task`, {
method: "POST",
headers: {
Authorization: config.CLICKUP_TOKEN,
"Content-Type": "application/json",
},
body,
}).then((res) => res.json());
},
async deleteTask(task_id) {
return await fetch(`https://api.clickup.com/api/v2/task/${task_id}`, {
method: "DELETE",
headers: {
Authorization: config.CLICKUP_TOKEN,
"Content-Type": "application/json",
},
}).then((res) => res.json());
},
};