0

Create reward redemption for a contact

by
Published Apr 8, 2025

Create reward redemption for a contact

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 reward redemption for a contact
7
 * Create reward redemption for a contact
8
 */
9
export async function main(
10
  auth: Brevo,
11
  loyaltyProgramId: string,
12
  body: {
13
    attributeRewardId?: string;
14
    code?: string;
15
    order?: {};
16
    meta?: {};
17
    contactId?: number;
18
    loyaltySubscriptionId?: string;
19
    ttl?: number;
20
  },
21
) {
22
  const url = new URL(
23
    `https://api.brevo.com/v3/loyalty/offer/programs/${loyaltyProgramId}/rewards/redeem`,
24
  );
25

26
  const response = await fetch(url, {
27
    method: "POST",
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