1 | |
2 | type Brex = { |
3 | token: string; |
4 | }; |
5 | |
6 | * |
7 | Create Budget Program |
8 |
|
9 | * |
10 | Creates a Budget Program |
11 |
|
12 | */ |
13 | export async function main( |
14 | auth: Brex, |
15 | Idempotency_Key: string, |
16 | body: { |
17 | existing_budget_ids?: string[]; |
18 | budget_blueprints: { |
19 | name: string; |
20 | description: string; |
21 | parent_budget_id: string; |
22 | owner_user_ids?: string[]; |
23 | period_type: "WEEKLY" | "MONTHLY" | "QUARTERLY" | "YEARLY" | "ONE_TIME"; |
24 | start_date?: string; |
25 | end_date?: string; |
26 | limit: { amount: number; currency?: string }; |
27 | limit_type: "HARD" | "SOFT"; |
28 | spend_type: |
29 | | "BUDGET_PROVISIONED_CARDS_ONLY" |
30 | | "NON_BUDGET_PROVISIONED_CARDS_ALLOWED"; |
31 | limit_visibility: "SHARED" | "PRIVATE"; |
32 | }[]; |
33 | employee_filter?: { |
34 | employment_status?: |
35 | | "EMPLOYMENT_STATUS_ACTIVE" |
36 | | "EMPLOYMENT_STATUS_INACTIVE" |
37 | | "EMPLOYMENT_STATUS_PENDING"; |
38 | employment_type?: |
39 | | "EMPLOYMENT_TYPE_FULL_TIME" |
40 | | "EMPLOYMENT_TYPE_PART_TIME" |
41 | | "EMPLOYMENT_TYPE_CONTRACTOR" |
42 | | "EMPLOYMENT_TYPE_INTERN" |
43 | | "EMPLOYMENT_TYPE_FREELANCE"; |
44 | }; |
45 | name: string; |
46 | description?: string; |
47 | }, |
48 | ) { |
49 | const url = new URL(`https://platform.brexapis.com/v1/budget_programs`); |
50 |
|
51 | const response = await fetch(url, { |
52 | method: "POST", |
53 | headers: { |
54 | "Idempotency-Key": Idempotency_Key, |
55 | "Content-Type": "application/json", |
56 | Authorization: "Bearer " + auth.token, |
57 | }, |
58 | body: JSON.stringify(body), |
59 | }); |
60 | if (!response.ok) { |
61 | const text = await response.text(); |
62 | throw new Error(`${response.status} ${text}`); |
63 | } |
64 | return await response.json(); |
65 | } |
66 |
|