1 | type Asana = { |
2 | token: string; |
3 | }; |
4 | |
5 | * Create a team |
6 | * Creates a team within the current workspace. |
7 | */ |
8 | export async function main( |
9 | auth: Asana, |
10 | opt_pretty: string | undefined, |
11 | opt_fields: string | undefined, |
12 | limit: string | undefined, |
13 | offset: string | undefined, |
14 | body: { |
15 | data?: ({ gid?: string; resource_type?: string; [k: string]: unknown } & { |
16 | name?: string; |
17 | [k: string]: unknown; |
18 | }) & { |
19 | description?: string; |
20 | html_description?: string; |
21 | organization?: string; |
22 | visibility?: "secret" | "request_to_join" | "public"; |
23 | [k: string]: unknown; |
24 | }; |
25 | [k: string]: unknown; |
26 | } |
27 | ) { |
28 | const url = new URL(`https://app.asana.com/api/1.0/teams`); |
29 | for (const [k, v] of [ |
30 | ["opt_pretty", opt_pretty], |
31 | ["opt_fields", opt_fields], |
32 | ["limit", limit], |
33 | ["offset", offset], |
34 | ]) { |
35 | if (v !== undefined && v !== "") { |
36 | url.searchParams.append(k, v); |
37 | } |
38 | } |
39 | const response = await fetch(url, { |
40 | method: "POST", |
41 | headers: { |
42 | "Content-Type": "application/json", |
43 | Authorization: "Bearer " + auth.token, |
44 | }, |
45 | body: JSON.stringify(body), |
46 | }); |
47 | if (!response.ok) { |
48 | const text = await response.text(); |
49 | throw new Error(`${response.status} ${text}`); |
50 | } |
51 | return await response.json(); |
52 | } |
53 |
|