1 | |
2 | type Smartsheet = { |
3 | token: string; |
4 | baseUrl: string; |
5 | }; |
6 | |
7 | * List Org Groups |
8 | * Gets a list of all groups in an organization account. To fetch the members of an individual group, use the Get Group operation. |
9 |
|
10 | */ |
11 | export async function main( |
12 | auth: Smartsheet, |
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}/groups`); |
20 | for (const [k, v] of [ |
21 | ["includeAll", includeAll], |
22 | ["modifiedSince", modifiedSince], |
23 | ["numericDates", numericDates], |
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 |
|