List cards

Lists all cards by a `user_id`. Only cards with `limit_type = CARD` have `spend_controls`

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
List cards
8

9
 * 
10
Lists all cards by a `user_id`.
11
Only cards with `limit_type = CARD` have `spend_controls`
12

13
 */
14
export async function main(
15
  auth: Brex,
16
  user_id: string | undefined,
17
  cursor: string | undefined,
18
  limit: string | undefined,
19
) {
20
  const url = new URL(`https://platform.brexapis.com/v2/cards`);
21
  for (const [k, v] of [
22
    ["user_id", user_id],
23
    ["cursor", cursor],
24
    ["limit", limit],
25
  ]) {
26
    if (v !== undefined && v !== "" && k !== undefined) {
27
      url.searchParams.append(k, v);
28
    }
29
  }
30
  const response = await fetch(url, {
31
    method: "GET",
32
    headers: {
33
      Authorization: "Bearer " + auth.token,
34
    },
35
    body: undefined,
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