Search.../

earnPoints( )

Developer Preview

Adds points to a loyalty account.

Description

The earnPoints() function returns a Promise that resolves to the updated loyalty account.

Only a positive amount can be added using the earnPoints() function, to manually adjust an account's balance for a negative amount, use adjustPoints().

The earnPoints() function allows customers to manually earn points to their loyalty accounts. To use this function you must include an appId and an idempotencyKey. Any string can be set as the appId or idempotencyKey. In contrast to when an account earns points through an action taken on your site, the appId automatically sets to the source app that generates the points. The transaction type is "EARN" for points earned this way.

Note: Only visitors with Manage Loyalty permissions can earn loyalty points.

Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function earnPoints(accountId: string, options: EarnPointsOptions): Promise<EarnPointsResponse>

earnPoints Parameters

NAME
TYPE
DESCRIPTION
accountId
string

Loyalty account ID.

options
EarnPointsOptions

Earn points info.

Returns

Return Type:

Promise<
EarnPointsResponse
>
NAME
TYPE
DESCRIPTION
account
LoyaltyAccount

Updated loyalty account.

Was this helpful?

Earn loyalty points

Copy Code
1import { accounts } from 'wix-loyalty.v2';
2
3/* Sample accountId value: '6d2c421e-3c1a-4464-bf2f-df13a3fc8aea'
4 *
5 * Sample options value:
6 * {
7 * 'amount': 50,
8 * 'description': 'Subscribed to newsletter.',
9 * 'appId': '553c79f3-5625-4f38-b14b-ef7c0d1e87df',
10 * 'idempotencyKey': 'bfdc785c-bbc6-447d-b987-220ca649a3b2'
11 * }
12 */
13
14export async function myEarnPointsFunction() {
15 try {
16 const updatedAccount = await accounts.earnPoints(accountId, options);
17
18 const newBalance = updatedAccount.account.points.balance;
19 const transactionId = updatedAccount.latestTransaction._id;
20
21 console.log('Success! New balance is ', newBalance);
22 return updatedAccount;
23 } catch (error) {
24 console.error(error);
25 }
26}
27
28/* Promise resolves to:
29 * {
30 * "account": {
31 * "_id": "6d2c421e-3c1a-4464-bf2f-df13a3fc8aea",
32 * "contactId": "7fa15d5e-49c4-44ef-8111-4cb0a04ca4db",
33 * "memberId": "7fa15d5e-49c4-44ef-8111-4cb0a04ca4db",
34 * "points": {
35 * "balance": 185,
36 * "earned": 185,
37 * "adjusted": 0,
38 * "redeemed": 0
39 * },
40 * "latestTransaction": {
41 * "_id": "4dd51f9d-2664-420a-9802-4df7811a5221",
42 * "amount": 50,
43 * "type": "EARN",
44 * "description": "Subscribed to newsletter.",
45 * "_createdDate": "2022-11-28T14:48:59.887Z",
46 * "appId": "553c79f3-5625-4f38-b14b-ef7c0d1e87df",
47 * "idempotencyKey": "bfdc785c-bbc6-447d-b987-220ca649a3b2"
48 * },
49 * "rewardAvailable": true,
50 * "_createdDate": "2022-11-09T15:18:53.582Z",
51 * "_updatedDate": "2022-11-28T14:48:59.940Z",
52 * "revision": "6",
53 * "tier": {
54 * "_updatedDate": "2022-11-28T14:48:59.939Z",
55 * "points": 185
56 * }
57 * }
58 * }
59 */
60