1 | |
2 | type Smartsheet = { |
3 | token: string; |
4 | baseUrl: string; |
5 | }; |
6 | |
7 | * List Dashboard Shares |
8 | * Gets a list of all users and groups to whom the specified dashboard is shared, and their access level. |
9 | */ |
10 | export async function main( |
11 | auth: Smartsheet, |
12 | sightId: string, |
13 | accessApiLevel: string | undefined, |
14 | sharingInclude: "ITEM" | "WORKSPACE" | undefined, |
15 | includeAll: string | undefined, |
16 | page: string | undefined, |
17 | pageSize: string | undefined, |
18 | ) { |
19 | const url = new URL(`${auth.baseUrl}/sights/${sightId}/shares`); |
20 | for (const [k, v] of [ |
21 | ["accessApiLevel", accessApiLevel], |
22 | ["sharingInclude", sharingInclude], |
23 | ["includeAll", includeAll], |
24 | ["page", page], |
25 | ["pageSize", pageSize], |
26 | ]) { |
27 | if (v !== undefined && v !== "" && k !== undefined) { |
28 | url.searchParams.append(k, v); |
29 | } |
30 | } |
31 | const response = await fetch(url, { |
32 | method: "GET", |
33 | headers: { |
34 | Authorization: "Bearer " + auth.token, |
35 | }, |
36 | body: undefined, |
37 | }); |
38 | if (!response.ok) { |
39 | const text = await response.text(); |
40 | throw new Error(`${response.status} ${text}`); |
41 | } |
42 | return await response.json(); |
43 | } |
44 |
|