0

Create balance limits

by
Published Apr 8, 2025

Creates balance limit and send the created UUID along with the data

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 limits
7
 * Creates balance limit and send the created UUID along with the data
8
 */
9
export async function main(
10
  auth: Brevo,
11
  loyaltyProgramId: string,
12
  balanceDefinitionId: string,
13
  body: {
14
    constraintType?: "amount" | "transaction";
15
    transactionType?: "debit" | "credit";
16
    durationValue?: number;
17
    durationUnit?: "day" | "week" | "month" | "year";
18
    value?: number;
19
  },
20
) {
21
  const url = new URL(
22
    `https://api.brevo.com/v3/loyalty/balance/programs/${loyaltyProgramId}/balance-definitions/${balanceDefinitionId}/limits`,
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