Invite user

This endpoint invites a new user as an employee. To update user's role, check out [this article](https://support.brex.com/how-do-i-change-another-user-s-role/).

Script brex Verified

by hugo697 ยท 10/17/2025

The script

Submitted by hugo697 Bun
Verified 217 days ago
1
//native
2
type Brex = {
3
  token: string;
4
};
5
/**
6
 * 
7
Invite user
8

9
 * 
10
This endpoint invites a new user as an employee.
11
To update user's role, check out [this article](https://support.brex.com/how-do-i-change-another-user-s-role/).
12

13
 */
14
export async function main(
15
  auth: Brex,
16
  body: {
17
    first_name: string;
18
    last_name: string;
19
    email: string;
20
    manager_id?: string;
21
    department_id?: string;
22
    location_id?: string;
23
    title_id?: string;
24
    metadata?: {};
25
  },
26
  Idempotency_Key?: string,
27
) {
28
  const url = new URL(`https://platform.brexapis.com/v2/users`);
29

30
  const response = await fetch(url, {
31
    method: "POST",
32
    headers: {
33
      ...(Idempotency_Key ? { "Idempotency-Key": Idempotency_Key } : {}),
34
      "Content-Type": "application/json",
35
      Authorization: "Bearer " + auth.token,
36
    },
37
    body: JSON.stringify(body),
38
  });
39
  if (!response.ok) {
40
    const text = await response.text();
41
    throw new Error(`${response.status} ${text}`);
42
  }
43
  return await response.json();
44
}
45