1 | type Asana = { |
2 | token: string; |
3 | }; |
4 | |
5 | * Create a goal |
6 | * Creates a new goal in a workspace or team. |
7 |
|
8 | Returns the full record of the newly created goal. |
9 | */ |
10 | export async function main( |
11 | auth: Asana, |
12 | opt_pretty: string | undefined, |
13 | opt_fields: string | undefined, |
14 | limit: string | undefined, |
15 | offset: string | undefined, |
16 | body: { |
17 | data?: ({ gid?: string; resource_type?: string; [k: string]: unknown } & { |
18 | due_on?: string; |
19 | html_notes?: string; |
20 | is_workspace_level?: boolean; |
21 | liked?: boolean; |
22 | name?: string; |
23 | notes?: string; |
24 | start_on?: string; |
25 | status?: string; |
26 | [k: string]: unknown; |
27 | }) & { |
28 | followers?: string[]; |
29 | owner?: string; |
30 | team?: string; |
31 | time_period?: string; |
32 | workspace?: string; |
33 | [k: string]: unknown; |
34 | }; |
35 | [k: string]: unknown; |
36 | } |
37 | ) { |
38 | const url = new URL(`https://app.asana.com/api/1.0/goals`); |
39 | for (const [k, v] of [ |
40 | ["opt_pretty", opt_pretty], |
41 | ["opt_fields", opt_fields], |
42 | ["limit", limit], |
43 | ["offset", offset], |
44 | ]) { |
45 | if (v !== undefined && v !== "") { |
46 | url.searchParams.append(k, v); |
47 | } |
48 | } |
49 | const response = await fetch(url, { |
50 | method: "POST", |
51 | headers: { |
52 | "Content-Type": "application/json", |
53 | Authorization: "Bearer " + auth.token, |
54 | }, |
55 | body: JSON.stringify(body), |
56 | }); |
57 | if (!response.ok) { |
58 | const text = await response.text(); |
59 | throw new Error(`${response.status} ${text}`); |
60 | } |
61 | return await response.json(); |
62 | } |
63 |
|