1 | |
2 | type Clickup = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update Task |
7 | * Update a task by including one or more fields in the request body. |
8 | */ |
9 | export async function main( |
10 | auth: Clickup, |
11 | task_id: string, |
12 | custom_task_ids: string | undefined, |
13 | team_id: string | undefined, |
14 | body: { |
15 | custom_item_id?: number; |
16 | name?: string; |
17 | description?: string; |
18 | markdown_content?: string; |
19 | status?: string; |
20 | priority?: number; |
21 | due_date?: number; |
22 | due_date_time?: false | true; |
23 | parent?: string; |
24 | time_estimate?: number; |
25 | start_date?: number; |
26 | start_date_time?: false | true; |
27 | points?: number; |
28 | assignees?: { add: number[]; rem: number[] }; |
29 | group_assignees?: { add?: number[]; rem?: number[] }; |
30 | watchers?: { add: number[]; rem: number[] }; |
31 | archived?: false | true; |
32 | }, |
33 | ) { |
34 | const url = new URL(`https://api.clickup.com/api/v2/task/${task_id}`); |
35 | for (const [k, v] of [ |
36 | ["custom_task_ids", custom_task_ids], |
37 | ["team_id", team_id], |
38 | ]) { |
39 | if (v !== undefined && v !== "" && k !== undefined) { |
40 | url.searchParams.append(k, v); |
41 | } |
42 | } |
43 | const response = await fetch(url, { |
44 | method: "PUT", |
45 | headers: { |
46 | "Content-Type": "application/json", |
47 | Authorization: auth.token, |
48 | }, |
49 | body: JSON.stringify(body), |
50 | }); |
51 | if (!response.ok) { |
52 | const text = await response.text(); |
53 | throw new Error(`${response.status} ${text}`); |
54 | } |
55 | return await response.json(); |
56 | } |
57 |
|