0

Create user invite

by
Published Oct 17, 2025

Invites an existing external user to join an enterprise. The existing user can not be part of another enterprise and must already have a Box account. Once invited, the user will receive an email and are prompted to accept the invitation within the Box web application. This method requires the "Manage An Enterprise" scope enabled for the application, which can be enabled within the developer console.

Script box Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Box = {
3
  token: string;
4
};
5
/**
6
 * Create user invite
7
 * Invites an existing external user to join an enterprise.
8

9
The existing user can not be part of another enterprise and
10
must already have a Box account. Once invited, the user will receive an
11
email and are prompted to accept the invitation within the
12
Box web application.
13

14
This method requires the "Manage An Enterprise" scope enabled for
15
the application, which can be enabled within the developer console.
16
 */
17
export async function main(
18
  auth: Box,
19
  fields: string | undefined,
20
  body: { enterprise: { id: string }; actionable_by: { login?: string } },
21
) {
22
  const url = new URL(`https://api.box.com/2.0/invites`);
23
  for (const [k, v] of [["fields", fields]]) {
24
    if (v !== undefined && v !== "" && k !== undefined) {
25
      url.searchParams.append(k, v);
26
    }
27
  }
28
  const response = await fetch(url, {
29
    method: "POST",
30
    headers: {
31
      "Content-Type": "application/json",
32
      Authorization: "Bearer " + auth.token,
33
    },
34
    body: JSON.stringify(body),
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42