1 | type Asana = { |
2 | token: string; |
3 | }; |
4 | |
5 | * Get workspace memberships for a user |
6 | * Returns the compact workspace membership records for the user. |
7 | */ |
8 | export async function main( |
9 | auth: Asana, |
10 | user_gid: string, |
11 | opt_pretty: string | undefined, |
12 | opt_fields: string | undefined, |
13 | limit: string | undefined, |
14 | offset: string | undefined |
15 | ) { |
16 | const url = new URL( |
17 | `https://app.asana.com/api/1.0/users/${user_gid}/workspace_memberships` |
18 | ); |
19 | for (const [k, v] of [ |
20 | ["opt_pretty", opt_pretty], |
21 | ["opt_fields", opt_fields], |
22 | ["limit", limit], |
23 | ["offset", offset], |
24 | ]) { |
25 | if (v !== undefined && v !== "") { |
26 | url.searchParams.append(k, v); |
27 | } |
28 | } |
29 | const response = await fetch(url, { |
30 | method: "GET", |
31 | headers: { |
32 | Authorization: "Bearer " + auth.token, |
33 | }, |
34 | body: undefined, |
35 | }); |
36 | if (!response.ok) { |
37 | const text = await response.text(); |
38 | throw new Error(`${response.status} ${text}`); |
39 | } |
40 | return await response.json(); |
41 | } |
42 |
|