1 | type Asana = { |
2 | token: string; |
3 | }; |
4 | |
5 | * Get status updates from an object |
6 | * Returns the compact status update records for all updates on the object. |
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 | parent: string | undefined, |
15 | created_since: string | undefined |
16 | ) { |
17 | const url = new URL(`https://app.asana.com/api/1.0/status_updates`); |
18 | for (const [k, v] of [ |
19 | ["opt_pretty", opt_pretty], |
20 | ["opt_fields", opt_fields], |
21 | ["limit", limit], |
22 | ["offset", offset], |
23 | ["parent", parent], |
24 | ["created_since", created_since], |
25 | ]) { |
26 | if (v !== undefined && v !== "") { |
27 | url.searchParams.append(k, v); |
28 | } |
29 | } |
30 | const response = await fetch(url, { |
31 | method: "GET", |
32 | headers: { |
33 | Authorization: "Bearer " + auth.token, |
34 | }, |
35 | body: undefined, |
36 | }); |
37 | if (!response.ok) { |
38 | const text = await response.text(); |
39 | throw new Error(`${response.status} ${text}`); |
40 | } |
41 | return await response.json(); |
42 | } |
43 |
|