0

Get user

by
Published Oct 17, 2025

Retrieves information about a user in the enterprise. The application and the authenticated user need to have the permission to look up users in the entire enterprise. This endpoint also returns a limited set of information for external users who are collaborated on content owned by the enterprise for authenticated users with the right scopes. In this case, disallowed fields will return null instead.

Script box Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Box = {
3
  token: string;
4
};
5
/**
6
 * Get user
7
 * Retrieves information about a user in the enterprise.
8

9
The application and the authenticated user need to
10
have the permission to look up users in the entire
11
enterprise.
12

13
This endpoint also returns a limited set of information
14
for external users who are collaborated on content
15
owned by the enterprise for authenticated users with the
16
right scopes. In this case, disallowed fields will return
17
null instead.
18
 */
19
export async function main(
20
  auth: Box,
21
  user_id: string,
22
  fields: string | undefined,
23
) {
24
  const url = new URL(`https://api.box.com/2.0/users/${user_id}`);
25
  for (const [k, v] of [["fields", fields]]) {
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