1 | |
2 | type Brex = { |
3 | token: string; |
4 | }; |
5 | |
6 | * |
7 | Create Budget |
8 |
|
9 | * |
10 | Creates a Budget |
11 |
|
12 | */ |
13 | export async function main( |
14 | auth: Brex, |
15 | Idempotency_Key: string, |
16 | body: { |
17 | name: string; |
18 | description: string; |
19 | parent_budget_id: string; |
20 | owner_user_ids?: string[]; |
21 | period_recurrence_type: |
22 | | ("MONTHLY" & {}) |
23 | | ("QUARTERLY" & {}) |
24 | | ("YEARLY" & {}) |
25 | | ("ONE_TIME" & {}); |
26 | amount: { amount: number; currency?: string }; |
27 | limit_type?: ("HARD" & {}) | ("SOFT" & {}); |
28 | start_date?: string; |
29 | end_date?: string; |
30 | }, |
31 | ) { |
32 | const url = new URL(`https://platform.brexapis.com/v2/budgets`); |
33 |
|
34 | const response = await fetch(url, { |
35 | method: "POST", |
36 | headers: { |
37 | "Idempotency-Key": Idempotency_Key, |
38 | "Content-Type": "application/json", |
39 | Authorization: "Bearer " + auth.token, |
40 | }, |
41 | body: JSON.stringify(body), |
42 | }); |
43 | if (!response.ok) { |
44 | const text = await response.text(); |
45 | throw new Error(`${response.status} ${text}`); |
46 | } |
47 | return await response.json(); |
48 | } |
49 |
|