Search.../

onAccountPointsUpdated( )

An event that triggers when the points of a loyalty account are adjusted, earned, or redeemed.

Description

The onAccountPointsUpdated() event handler runs when the points of a loyalty account are adjusted, earned, or redeemed. The received AccountPointsUpdated object contains information about the loyalty account that was updated.

Note: Backend events don't work when previewing your site.

Syntax

function wixLoyalty_onAccountPointsUpdated(event: AccountPointsUpdated): void

onAccountPointsUpdated Parameters

NAME
TYPE
DESCRIPTION
event
Optional
AccountPointsUpdated

Returns

This function does not return anything.

Return Type:

void

Was this helpful?

An event that triggered when a the points of a loyalty account is updated

Copy Code
1// Place this code in the events.js file
2// of your site's Backend section.
3// Add the file if it doesn't exist.
4
5export function wixLoyalty_onAccountPointsUpdated(event) {
6 const eventId = event.metadata.id;
7 const accountBalance = event.data.account.points.balance;
8 const recentTransaction = event.data.account.latestTransaction;
9
10 console.log('Current account balance: ', accountBalance);
11 console.log('Latest transaction in this account: ', recentTransaction);
12 console.log(event);
13}
14
15/* Full event object:
16 * {
17 * "metadata": {
18 * "id":"447912e4-b460-4eba-9bd2-3c19b64ddce0",
19 * "entityId":"1ab8f49c-a329-4ddc-a31d-814afbb3b565",
20 * "eventTime":"2023-01-18T13:16:53.000613Z",
21 * "triggeredByAnonymizeRequest":false
22 * },
23 * "data": {
24 * "account": {
25 * "_id":"1ab8f49c-a329-4ddc-a31d-814afbb3b565",
26 * "contactId":"3128dc64-74fc-442f-aa32-e8e871dad141",
27 * "memberId":"3128dc64-74fc-442f-aa32-e8e871dad141",
28 * "points": {
29 * "balance":95,
30 * "earned":45,
31 * "adjusted":50,
32 * "redeemed":0
33 * },
34 * "latestTransaction": {
35 * "_id":"b28f7f95-458e-49e1-89a1-78642a453744",
36 * "amount":50,
37 * "type":"GIVE",
38 * "description":"",
39 * "_createdDate":"2023-01-18T13:16:52.021Z",
40 * "appId":"553c79f3-5625-4f38-b14b-ef7c0d1e87df"
41 * },
42 * "rewardAvailable":true,
43 * "_createdDate":"2022-11-28T11:57:30.722Z",
44 * "_updatedDate":"2023-01-18T13:16:52.982Z",
45 * "lastActivityDate":"2023-01-18T13:16:52.980Z",
46 * "revision":"13",
47 * "tier": {
48 * "_id":"a8a2bc2b-6957-40a6-9f20-a1bfe52d14de",
49 * "_updatedDate":"2023-01-18T13:16:52.980Z",
50 * "points":95
51 * }
52 * }
53 * }
54 * }
55 */