List card expenses

List card expenses under the same account. Admin and bookkeeper have access to any expense, and regular users can only access their own.

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
 * List card expenses
7
 * List card expenses under the same account. Admin and bookkeeper have access to any expense, and regular users can only access their own.
8
 */
9
export async function main(
10
  auth: Brex,
11
  expand__: string | undefined,
12
  user_id__: string | undefined,
13
  parent_expense_id__: string | undefined,
14
  budget_id__: string | undefined,
15
  spending_entity_id__: string | undefined,
16
  status__: string | undefined,
17
  payment_status__: string | undefined,
18
  purchased_at_start: string | undefined,
19
  purchased_at_end: string | undefined,
20
  updated_at_start: string | undefined,
21
  updated_at_end: string | undefined,
22
  load_custom_fields: string | undefined,
23
  cursor: string | undefined,
24
  limit: string | undefined,
25
) {
26
  const url = new URL(`https://platform.brexapis.com/v1/expenses/card`);
27
  for (const [k, v] of [
28
    ["expand[]", expand__],
29
    ["user_id[]", user_id__],
30
    ["parent_expense_id[]", parent_expense_id__],
31
    ["budget_id[]", budget_id__],
32
    ["spending_entity_id[]", spending_entity_id__],
33
    ["status[]", status__],
34
    ["payment_status[]", payment_status__],
35
    ["purchased_at_start", purchased_at_start],
36
    ["purchased_at_end", purchased_at_end],
37
    ["updated_at_start", updated_at_start],
38
    ["updated_at_end", updated_at_end],
39
    ["load_custom_fields", load_custom_fields],
40
    ["cursor", cursor],
41
    ["limit", limit],
42
  ]) {
43
    if (v !== undefined && v !== "" && k !== undefined) {
44
      url.searchParams.append(k, v);
45
    }
46
  }
47
  const response = await fetch(url, {
48
    method: "GET",
49
    headers: {
50
      Authorization: "Bearer " + auth.token,
51
    },
52
    body: undefined,
53
  });
54
  if (!response.ok) {
55
    const text = await response.text();
56
    throw new Error(`${response.status} ${text}`);
57
  }
58
  return await response.json();
59
}
60