0

Updates balance limit

by
Published Apr 8, 2025

Updates balance limit

Script brevo Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Brevo = {
3
  apiKey: string;
4
};
5
/**
6
 * Updates balance limit
7
 * Updates balance limit
8
 */
9
export async function main(
10
  auth: Brevo,
11
  loyaltyProgramId: string,
12
  balanceDefinitionId: string,
13
  balanceLimitId: string,
14
  body: {
15
    constraintType?: "amount" | "transaction";
16
    transactionType?: "debit" | "credit";
17
    durationValue?: number;
18
    durationUnit?: "day" | "week" | "month" | "year";
19
    value?: number;
20
  },
21
) {
22
  const url = new URL(
23
    `https://api.brevo.com/v3/loyalty/balance/programs/${loyaltyProgramId}/balance-definitions/${balanceDefinitionId}/limits/${balanceLimitId}`,
24
  );
25

26
  const response = await fetch(url, {
27
    method: "PUT",
28
    headers: {
29
      "Content-Type": "application/json",
30
      "api-key": auth.apiKey,
31
    },
32
    body: JSON.stringify(body),
33
  });
34
  if (!response.ok) {
35
    const text = await response.text();
36
    throw new Error(`${response.status} ${text}`);
37
  }
38
  return await response.json();
39
}
40