Set limit for the user

This endpoint sets the monthly limit for a user. The limit amount must be non-negative. To unset the monthly limit of the user, just set `monthly_limit` to null.

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
Set limit for the user
8

9
 * 
10
This endpoint sets the monthly limit for a user. 
11
The limit amount must be non-negative. 
12
To unset the monthly limit of the user, just set `monthly_limit` to null.
13

14
 */
15
export async function main(
16
  auth: Brex,
17
  id: string,
18
  body: { monthly_limit?: { amount?: number; currency?: string } & {} },
19
  Idempotency_Key?: string,
20
) {
21
  const url = new URL(`https://platform.brexapis.com/v2/users/${id}/limit`);
22

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