1 | type Asana = { |
2 | token: string; |
3 | }; |
4 | |
5 | * Get multiple tags |
6 | * Returns the compact tag records for some filtered set of tags. Use one or more of the parameters provided to filter the tags returned. |
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 | workspace: string | undefined |
15 | ) { |
16 | const url = new URL(`https://app.asana.com/api/1.0/tags`); |
17 | for (const [k, v] of [ |
18 | ["opt_pretty", opt_pretty], |
19 | ["opt_fields", opt_fields], |
20 | ["limit", limit], |
21 | ["offset", offset], |
22 | ["workspace", workspace], |
23 | ]) { |
24 | if (v !== undefined && v !== "") { |
25 | url.searchParams.append(k, v); |
26 | } |
27 | } |
28 | const response = await fetch(url, { |
29 | method: "GET", |
30 | headers: { |
31 | Authorization: "Bearer " + auth.token, |
32 | }, |
33 | body: undefined, |
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 |
|