1 | |
2 | type Smartsheet = { |
3 | token: string; |
4 | baseUrl: string; |
5 | }; |
6 | |
7 | * List Dashboards |
8 | * Gets a list of all dashboards that the user has access to. |
9 | */ |
10 | export async function main( |
11 | auth: Smartsheet, |
12 | accessApiLevel: string | undefined, |
13 | includeAll: string | undefined, |
14 | modifiedSince: string | undefined, |
15 | numericDates: string | undefined, |
16 | page: string | undefined, |
17 | pageSize: string | undefined, |
18 | ) { |
19 | const url = new URL(`${auth.baseUrl}/sights`); |
20 | for (const [k, v] of [ |
21 | ["accessApiLevel", accessApiLevel], |
22 | ["includeAll", includeAll], |
23 | ["modifiedSince", modifiedSince], |
24 | ["numericDates", numericDates], |
25 | ["page", page], |
26 | ["pageSize", pageSize], |
27 | ]) { |
28 | if (v !== undefined && v !== "" && k !== undefined) { |
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 |
|