0

Update user

by
Published Oct 17, 2025

Updates a managed or app user in an enterprise. This endpoint is only available to users and applications with the right admin permissions.

Script box Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Box = {
3
  token: string;
4
};
5
/**
6
 * Update user
7
 * Updates a managed or app 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
  user_id: string,
14
  fields: string | undefined,
15
  body: {
16
    enterprise?: string;
17
    notify?: false | true;
18
    name?: string;
19
    login?: string;
20
    role?: "coadmin" | "user";
21
    language?: string;
22
    is_sync_enabled?: false | true;
23
    job_title?: string;
24
    phone?: string;
25
    address?: string;
26
    tracking_codes?: {
27
      type?: "tracking_code";
28
      name?: string;
29
      value?: string;
30
    }[];
31
    can_see_managed_users?: false | true;
32
    timezone?: string;
33
    is_external_collab_restricted?: false | true;
34
    is_exempt_from_device_limits?: false | true;
35
    is_exempt_from_login_verification?: false | true;
36
    is_password_reset_required?: false | true;
37
    status?:
38
      | "active"
39
      | "inactive"
40
      | "cannot_delete_edit"
41
      | "cannot_delete_edit_upload";
42
    space_amount?: number;
43
    notification_email?: { email?: string };
44
    external_app_user_id?: string;
45
  },
46
) {
47
  const url = new URL(`https://api.box.com/2.0/users/${user_id}`);
48
  for (const [k, v] of [["fields", fields]]) {
49
    if (v !== undefined && v !== "" && k !== undefined) {
50
      url.searchParams.append(k, v);
51
    }
52
  }
53
  const response = await fetch(url, {
54
    method: "PUT",
55
    headers: {
56
      "Content-Type": "application/json",
57
      Authorization: "Bearer " + auth.token,
58
    },
59
    body: JSON.stringify(body),
60
  });
61
  if (!response.ok) {
62
    const text = await response.text();
63
    throw new Error(`${response.status} ${text}`);
64
  }
65
  return await response.json();
66
}
67