Update user

This endpoint updates a user. Any parameters not provided will be left unchanged.

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
Update user
8

9
 * 
10
This endpoint updates a user. Any parameters not provided will be left unchanged.
11

12
 */
13
export async function main(
14
  auth: Brex,
15
  id: string,
16
  body: {
17
    status?: ("ACTIVE" & {}) | ("DISABLED" & {});
18
    manager_id?: string;
19
    department_id?: string;
20
    location_id?: string;
21
    title_id?: string;
22
    metadata?: {};
23
  },
24
  Idempotency_Key?: string,
25
) {
26
  const url = new URL(`https://platform.brexapis.com/v2/users/${id}`);
27

28
  const response = await fetch(url, {
29
    method: "PUT",
30
    headers: {
31
      ...(Idempotency_Key ? { "Idempotency-Key": Idempotency_Key } : {}),
32
      "Content-Type": "application/json",
33
      Authorization: "Bearer " + auth.token,
34
    },
35
    body: JSON.stringify(body),
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