0

Update an expense

by
Published Oct 17, 2025

Update an expense. Admin and bookkeeper have access to any expense, and regular users can only access their own.

Script brex Verified

The script

Submitted by hugo697 Bun
Verified 238 days ago
1
//native
2
type Brex = {
3
  token: string;
4
};
5
/**
6
 * Update an expense
7
 * Update an expense. 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
  expense_id: string,
12
  body: { memo?: string },
13
) {
14
  const url = new URL(
15
    `https://platform.brexapis.com/v1/expenses/card/${expense_id}`,
16
  );
17

18
  const response = await fetch(url, {
19
    method: "PUT",
20
    headers: {
21
      "Content-Type": "application/json",
22
      Authorization: "Bearer " + auth.token,
23
    },
24
    body: JSON.stringify(body),
25
  });
26
  if (!response.ok) {
27
    const text = await response.text();
28
    throw new Error(`${response.status} ${text}`);
29
  }
30
  return await response.json();
31
}
32