1 | |
2 | type Clickup = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create Key Result |
7 | * Add a Target to a Goal. |
8 | */ |
9 | export async function main( |
10 | auth: Clickup, |
11 | goal_id: string, |
12 | body: { |
13 | name: string; |
14 | owners: number[]; |
15 | type: string; |
16 | steps_start: number; |
17 | steps_end: number; |
18 | unit: string; |
19 | task_ids: string[]; |
20 | list_ids: string[]; |
21 | }, |
22 | ) { |
23 | const url = new URL( |
24 | `https://api.clickup.com/api/v2/goal/${goal_id}/key_result`, |
25 | ); |
26 |
|
27 | const response = await fetch(url, { |
28 | method: "POST", |
29 | headers: { |
30 | "Content-Type": "application/json", |
31 | Authorization: auth.token, |
32 | }, |
33 | body: JSON.stringify(body), |
34 | }); |
35 | if (!response.ok) { |
36 | const text = await response.text(); |
37 | throw new Error(`${response.status} ${text}`); |
38 | } |
39 | return await response.json(); |
40 | } |
41 |
|