Update Budget

Updates a Budget

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

9
 * 
10
Updates a Budget
11

12
 */
13
export async function main(
14
  auth: Brex,
15
  id: string,
16
  Idempotency_Key: string,
17
  body: {
18
    name?: string;
19
    description?: string;
20
    parent_budget_id?: string;
21
    owner_user_ids?: string[];
22
    period_recurrence_type?:
23
      | ("MONTHLY" & {})
24
      | ("QUARTERLY" & {})
25
      | ("YEARLY" & {})
26
      | ("ONE_TIME" & {});
27
    amount?: { amount: number; currency?: string } & {};
28
    limit_type?: ("HARD" & {}) | ("SOFT" & {});
29
    start_date?: string;
30
    end_date?: string;
31
  },
32
) {
33
  const url = new URL(`https://platform.brexapis.com/v2/budgets/${id}`);
34

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