0

Create balance order

by
Published Apr 8, 2025

Returns created order

Script brevo Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
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