0

List enterprise users

by
Published Oct 17, 2025

Returns a list of all users for the Enterprise along with their `user_id`, `public_name`, and `login`. The application and the authenticated user need to have the permission to look up users in the entire enterprise.

Script box Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Box = {
3
  token: string;
4
};
5
/**
6
 * List enterprise users
7
 * Returns a list of all users for the Enterprise along with their `user_id`,
8
`public_name`, and `login`.
9

10
The application and the authenticated user need to
11
have the permission to look up users in the entire
12
enterprise.
13
 */
14
export async function main(
15
  auth: Box,
16
  filter_term: string | undefined,
17
  user_type: "all" | "managed" | "external" | undefined,
18
  external_app_user_id: string | undefined,
19
  fields: string | undefined,
20
  offset: string | undefined,
21
  limit: string | undefined,
22
  usemarker: string | undefined,
23
  marker: string | undefined,
24
) {
25
  const url = new URL(`https://api.box.com/2.0/users`);
26
  for (const [k, v] of [
27
    ["filter_term", filter_term],
28
    ["user_type", user_type],
29
    ["external_app_user_id", external_app_user_id],
30
    ["fields", fields],
31
    ["offset", offset],
32
    ["limit", limit],
33
    ["usemarker", usemarker],
34
    ["marker", marker],
35
  ]) {
36
    if (v !== undefined && v !== "" && k !== undefined) {
37
      url.searchParams.append(k, v);
38
    }
39
  }
40
  const response = await fetch(url, {
41
    method: "GET",
42
    headers: {
43
      Authorization: "Bearer " + auth.token,
44
    },
45
    body: undefined,
46
  });
47
  if (!response.ok) {
48
    const text = await response.text();
49
    throw new Error(`${response.status} ${text}`);
50
  }
51
  return await response.json();
52
}
53