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