1 | |
2 | type Brevo = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Create balance order |
7 | * Returns created order |
8 | */ |
9 | export async function main( |
10 | auth: Brevo, |
11 | loyaltyProgramId: string, |
12 | body: { |
13 | amount: number; |
14 | dueAt: string; |
15 | expiresAt?: string; |
16 | meta?: {}; |
17 | contactId: number; |
18 | balanceDefinitionId: string; |
19 | }, |
20 | ) { |
21 | const url = new URL( |
22 | `https://api.brevo.com/v3/loyalty/balance/programs/${loyaltyProgramId}/create-order`, |
23 | ); |
24 |
|
25 | const response = await fetch(url, { |
26 | method: "POST", |
27 | headers: { |
28 | "Content-Type": "application/json", |
29 | "api-key": auth.apiKey, |
30 | }, |
31 | body: JSON.stringify(body), |
32 | }); |
33 | if (!response.ok) { |
34 | const text = await response.text(); |
35 | throw new Error(`${response.status} ${text}`); |
36 | } |
37 | return await response.json(); |
38 | } |
39 |
|