1 | |
2 | type Smartsheet = { |
3 | token: string; |
4 | baseUrl: string; |
5 | }; |
6 | |
7 | * List Users |
8 | * Gets a list of users in the organization account. |
9 | */ |
10 | export async function main( |
11 | auth: Smartsheet, |
12 | email: string | undefined, |
13 | include: string | undefined, |
14 | includeAll: string | undefined, |
15 | modifiedSince: string | undefined, |
16 | numericDates: string | undefined, |
17 | page: string | undefined, |
18 | pageSize: string | undefined, |
19 | ) { |
20 | const url = new URL(`${auth.baseUrl}/users`); |
21 | for (const [k, v] of [ |
22 | ["email", email], |
23 | ["include", include], |
24 | ["includeAll", includeAll], |
25 | ["modifiedSince", modifiedSince], |
26 | ["numericDates", numericDates], |
27 | ["page", page], |
28 | ["pageSize", pageSize], |
29 | ]) { |
30 | if (v !== undefined && v !== "" && k !== undefined) { |
31 | url.searchParams.append(k, v); |
32 | } |
33 | } |
34 | const response = await fetch(url, { |
35 | method: "GET", |
36 | headers: { |
37 | Authorization: "Bearer " + auth.token, |
38 | }, |
39 | body: undefined, |
40 | }); |
41 | if (!response.ok) { |
42 | const text = await response.text(); |
43 | throw new Error(`${response.status} ${text}`); |
44 | } |
45 | return await response.json(); |
46 | } |
47 |
|