1 | |
2 | type Smartsheet = { |
3 | token: string; |
4 | baseUrl: string; |
5 | }; |
6 | |
7 | * Get Dashboard |
8 | * Gets the specified dashboard. |
9 | */ |
10 | export async function main( |
11 | auth: Smartsheet, |
12 | sightId: string, |
13 | accessApiLevel: string | undefined, |
14 | include: "objectValue" | "source" | undefined, |
15 | level: string | undefined, |
16 | numericDates: string | undefined, |
17 | ) { |
18 | const url = new URL(`${auth.baseUrl}/sights/${sightId}`); |
19 | for (const [k, v] of [ |
20 | ["accessApiLevel", accessApiLevel], |
21 | ["include", include], |
22 | ["level", level], |
23 | ["numericDates", numericDates], |
24 | ]) { |
25 | if (v !== undefined && v !== "" && k !== undefined) { |
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 |
|