Update card

Update an existing vendor card

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 card
8

9
 * 
10
Update an existing vendor card
11

12
 */
13
export async function main(
14
  auth: Brex,
15
  id: string,
16
  body: {
17
    spend_controls?: {
18
      spend_limit?: { amount?: number; currency?: string } & {};
19
      spend_duration?:
20
        | ("MONTHLY" & {})
21
        | ("QUARTERLY" & {})
22
        | ("YEARLY" & {})
23
        | ("ONE_TIME" & {});
24
      reason?: string;
25
      lock_after_date?: string;
26
    } & {};
27
    metadata?: {};
28
  },
29
  Idempotency_Key?: string,
30
) {
31
  const url = new URL(`https://platform.brexapis.com/v2/cards/${id}`);
32

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