1 | |
2 | type Box = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create user |
7 | * Creates a new managed user in an enterprise. This endpoint |
8 | is only available to users and applications with the right |
9 | admin permissions. |
10 | */ |
11 | export async function main( |
12 | auth: Box, |
13 | fields: string | undefined, |
14 | body: { |
15 | name: string; |
16 | login?: string; |
17 | is_platform_access_only?: false | true; |
18 | role?: "coadmin" | "user"; |
19 | language?: string; |
20 | is_sync_enabled?: false | true; |
21 | job_title?: string; |
22 | phone?: string; |
23 | address?: string; |
24 | space_amount?: number; |
25 | tracking_codes?: { |
26 | type?: "tracking_code"; |
27 | name?: string; |
28 | value?: string; |
29 | }[]; |
30 | can_see_managed_users?: false | true; |
31 | timezone?: string; |
32 | is_external_collab_restricted?: false | true; |
33 | is_exempt_from_device_limits?: false | true; |
34 | is_exempt_from_login_verification?: false | true; |
35 | status?: |
36 | | "active" |
37 | | "inactive" |
38 | | "cannot_delete_edit" |
39 | | "cannot_delete_edit_upload"; |
40 | external_app_user_id?: string; |
41 | }, |
42 | ) { |
43 | const url = new URL(`https://api.box.com/2.0/users`); |
44 | for (const [k, v] of [["fields", fields]]) { |
45 | if (v !== undefined && v !== "" && k !== undefined) { |
46 | url.searchParams.append(k, v); |
47 | } |
48 | } |
49 | const response = await fetch(url, { |
50 | method: "POST", |
51 | headers: { |
52 | "Content-Type": "application/json", |
53 | Authorization: "Bearer " + auth.token, |
54 | }, |
55 | body: JSON.stringify(body), |
56 | }); |
57 | if (!response.ok) { |
58 | const text = await response.text(); |
59 | throw new Error(`${response.status} ${text}`); |
60 | } |
61 | return await response.json(); |
62 | } |
63 |
|