Update Budget Program

Updates a Budget Program

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

9
 * 
10
Updates a Budget Program
11

12
 */
13
export async function main(
14
  auth: Brex,
15
  id: string,
16
  Idempotency_Key: string,
17
  body: {
18
    existing_budget_ids?: string[];
19
    budget_blueprints?: {
20
      id?: string;
21
      name?: string;
22
      description?: string;
23
      parent_budget_id?: string;
24
      owner_user_ids?: string[];
25
      period_type?: "WEEKLY" | "MONTHLY" | "QUARTERLY" | "YEARLY" | "ONE_TIME";
26
      start_date?: string;
27
      end_date?: string;
28
      limit?: { amount: number; currency?: string };
29
      limit_type?: "HARD" | "SOFT";
30
      spend_type?:
31
        | "BUDGET_PROVISIONED_CARDS_ONLY"
32
        | "NON_BUDGET_PROVISIONED_CARDS_ALLOWED";
33
    }[];
34
    employee_filter?: {
35
      employment_status?:
36
        | "EMPLOYMENT_STATUS_ACTIVE"
37
        | "EMPLOYMENT_STATUS_INACTIVE"
38
        | "EMPLOYMENT_STATUS_PENDING";
39
      employment_type?:
40
        | "EMPLOYMENT_TYPE_FULL_TIME"
41
        | "EMPLOYMENT_TYPE_PART_TIME"
42
        | "EMPLOYMENT_TYPE_CONTRACTOR"
43
        | "EMPLOYMENT_TYPE_INTERN"
44
        | "EMPLOYMENT_TYPE_FREELANCE";
45
    };
46
    name?: string;
47
    description?: string;
48
  },
49
) {
50
  const url = new URL(`https://platform.brexapis.com/v1/budget_programs/${id}`);
51

52
  const response = await fetch(url, {
53
    method: "PUT",
54
    headers: {
55
      "Idempotency-Key": Idempotency_Key,
56
      "Content-Type": "application/json",
57
      Authorization: "Bearer " + auth.token,
58
    },
59
    body: JSON.stringify(body),
60
  });
61
  if (!response.ok) {
62
    const text = await response.text();
63
    throw new Error(`${response.status} ${text}`);
64
  }
65
  return await response.json();
66
}
67