1 | |
2 | type Smartsheet = { |
3 | token: string; |
4 | baseUrl: string; |
5 | }; |
6 | |
7 | * Add User |
8 | * Adds a user to the organization account. |
9 | */ |
10 | export async function main( |
11 | auth: Smartsheet, |
12 | sendEmail: string | undefined, |
13 | body: { |
14 | id?: number; |
15 | admin?: false | true; |
16 | customWelcomeScreenViewed?: string; |
17 | email?: string; |
18 | firstName?: string; |
19 | groupAdmin?: false | true; |
20 | lastLogin?: string; |
21 | lastName?: string; |
22 | licensedSheetCreator?: false | true; |
23 | name?: string; |
24 | profileImage?: { imageId?: string; height?: string; width?: string }; |
25 | resourceViewer?: false | true; |
26 | sheetCount?: number; |
27 | status?: "ACTIVE" | "DECLINED" | "PENDING" | "DEACTIVATED"; |
28 | }, |
29 | ) { |
30 | const url = new URL(`${auth.baseUrl}/users`); |
31 | for (const [k, v] of [["sendEmail", sendEmail]]) { |
32 | if (v !== undefined && v !== "" && k !== undefined) { |
33 | url.searchParams.append(k, v); |
34 | } |
35 | } |
36 | const response = await fetch(url, { |
37 | method: "POST", |
38 | headers: { |
39 | "Content-Type": "application/json", |
40 | Authorization: "Bearer " + auth.token, |
41 | }, |
42 | body: JSON.stringify(body), |
43 | }); |
44 | if (!response.ok) { |
45 | const text = await response.text(); |
46 | throw new Error(`${response.status} ${text}`); |
47 | } |
48 | return await response.json(); |
49 | } |
50 |
|