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