0

Update balance definition

by
Published Apr 8, 2025

Updates Balance definition

Script brevo Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Brevo = {
3
  apiKey: string;
4
};
5
/**
6
 * Update balance definition
7
 * Updates Balance definition
8
 */
9
export async function main(
10
  auth: Brevo,
11
  loyaltyProgramId: string,
12
  balanceDefinitionId: string,
13
  body: {
14
    name: string;
15
    description?: string;
16
    meta?: {};
17
    unit:
18
      | "points"
19
      | "EUR"
20
      | "USD"
21
      | "MXN"
22
      | "GBP"
23
      | "INR"
24
      | "CAD"
25
      | "SGD"
26
      | "RON"
27
      | "JPY"
28
      | "MYR"
29
      | "CLP"
30
      | "PEN"
31
      | "MAD"
32
      | "AUD"
33
      | "CHF"
34
      | "BRL";
35
    minAmount?: number;
36
    maxAmount?: number;
37
    maxCreditAmountLimit?: number;
38
    maxDebitAmountLimit?: number;
39
    balanceOptionAmountOvertakingStrategy?: "strict" | "partial";
40
    balanceOptionCreditRounding?: "natural" | "upper" | "lower";
41
    balanceOptionDebitRounding?: "natural" | "upper" | "lower";
42
    balanceAvailabilityDurationValue?: number;
43
    balanceAvailabilityDurationUnit?: "day" | "week" | "month" | "year";
44
    balanceAvailabilityDurationModifier?:
45
      | "startOfPeriod"
46
      | "endOfPeriod"
47
      | "noModification";
48
    balanceExpirationDate?: string;
49
  },
50
) {
51
  const url = new URL(
52
    `https://api.brevo.com/v3/loyalty/balance/programs/${loyaltyProgramId}/balance-definitions/${balanceDefinitionId}`,
53
  );
54

55
  const response = await fetch(url, {
56
    method: "PUT",
57
    headers: {
58
      "Content-Type": "application/json",
59
      "api-key": auth.apiKey,
60
    },
61
    body: JSON.stringify(body),
62
  });
63
  if (!response.ok) {
64
    const text = await response.text();
65
    throw new Error(`${response.status} ${text}`);
66
  }
67
  return await response.json();
68
}
69