Lock card

Locks an existing, unlocked card. And the card owner will receive a notification about it.

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

9
 * 
10
Locks an existing, unlocked card. And the card owner will receive a notification about it.
11

12
 */
13
export async function main(
14
  auth: Brex,
15
  id: string,
16
  body: {
17
    description?: string;
18
    reason:
19
      | "CARD_DAMAGED"
20
      | "CARD_LOST"
21
      | "CARD_NOT_RECEIVED"
22
      | "DO_NOT_NEED_PHYSICAL_CARD"
23
      | "DO_NOT_NEED_VIRTUAL_CARD"
24
      | "FRAUD"
25
      | "OTHER";
26
  },
27
  Idempotency_Key?: string,
28
) {
29
  const url = new URL(`https://platform.brexapis.com/v2/cards/${id}/lock`);
30

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