0

Update tier

by
Published Apr 8, 2025

Modifies an existing tier for the specified tier group

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 tier
7
 * Modifies an existing tier for the specified tier group
8
 */
9
export async function main(
10
  auth: Brevo,
11
  loyaltyProgramId: string,
12
  tierId: string,
13
  body: {
14
    name: string;
15
    accessConditions: { balanceDefinitionId?: string; minimumValue?: number }[];
16
    tierRewards?: { rewardId?: string }[];
17
  },
18
) {
19
  const url = new URL(
20
    `https://api.brevo.com/v3/loyalty/tier/programs/${loyaltyProgramId}/tiers/${tierId}`,
21
  );
22

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