Search.../

adjustPoints( )

Developer Preview

Adjusts the point balance of a loyalty account.

Description

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

To adjust the points balance of an account you must include an accountId, a revision number, and the adjustment to make. You can also leave a description to explain the reason for the points adjustment.

There are two ways to adjust the points of a loyalty account:

  • balance allows you to set the total points balance to this new amount. The transaction type will return as "ADJUST".
  • amount allows you to alter the points balance by this amount. This amount can be a positive number to increase the points balance or a negative number to decrease the balance. The transaction type will return as "GIVE".

An account may not be adjusted to a negative balance. If you pass values in both the balance and the amount parameters then the balance adjustment takes effect and the amount adjustment is ignored.

Note: Only visitors with Manage Loyalty permissions can manually adjust points in a loyalty account.

Admin Method

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

Syntax

function adjustPoints(accountId: string, options: AdjustPointsOptions): Promise<AdjustPointsResponse>

adjustPoints Parameters

NAME
TYPE
DESCRIPTION
accountId
string

Loyalty account ID.

options
Optional
AdjustPointsOptions

Options to use when adjusting points.

Returns

Return Type:

Promise<
AdjustPointsResponse
>
NAME
TYPE
DESCRIPTION
account
LoyaltyAccount

Adjusted loyalty account.

Was this helpful?

Adjust loyalty account balance (dashboard page code)

Copy Code
1import { accounts } from 'wix-loyalty.v2';
2
3// Sample accountId value: "1ab8f49c-a329-4ddc-a31d-814afbb3b565";
4
5/* Sample options values:
6 * {
7 * balance: 715,
8 * description: "Sync from external program.",
9 * revision: "3"
10 * };
11 */
12
13export async function myAdjustPointsFunction(accountId, options) {
14 try {
15 const updatedAccount = await accounts.adjustPoints(accountId, options);
16
17 const updatedBalance = updatedAccount.account.points.balance;
18 const transactionId = updatedAccount.account.latestTransaction._id;
19
20 console.log('Success! New account balance is: ', updatedBalance, ' The ID for this transaction is: ', transactionId);
21
22 return updatedAccount;
23 } catch (error) {
24 console.error(error);
25 }
26}
27
28/* Promise resolves to:
29 * {
30 * "account": {
31 * "_id": "1ab8f49c-a329-4ddc-a31d-814afbb3b565",
32 * "contactId": "3128dc64-74fc-442f-aa32-e8e871dad141",
33 * "memberId": "3128dc64-74fc-442f-aa32-e8e871dad141",
34 * "points": {
35 * "balance": 715,
36 * "earned": 0,
37 * "adjusted": 715,
38 * "redeemed": 0
39 * },
40 * "latestTransaction": {
41 * "_id": "da9096b4-a7fe-41a0-bf3b-05c22e3102fb",
42 * "amount": 715,
43 * "type": "ADJUST",
44 * "description": "Sync from external program.",
45 * "_createdDate": "2023-01-17T12:04:49.171Z",
46 * "appId": "553c79f3-5625-4f38-b14b-ef7c0d1e87df"
47 * },
48 * "rewardAvailable": false,
49 * "_createdDate": "2022-11-28T11:57:30.722Z",
50 * "_updatedDate": "2023-01-17T12:04:49.620Z",
51 * "lastActivityDate": "2023-01-17T12:04:49.619Z",
52 * "revision": "2",
53 * "tier": {
54 * "_id": "05e9d924-54c4-4540-94ef-8edd1e303611",
55 * "_updatedDate": "2023-01-17T12:04:49.619Z",
56 * "points": 715
57 * }
58 * }
59 * }
60 */
61
Adjust loyalty account balance (export from backend code)

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { accounts } from 'wix-loyalty.v2';
3
4// Sample accountId value: "1ab8f49c-a329-4ddc-a31d-814afbb3b565";
5
6/* Sample options values:
7 * {
8 * balance: 715,
9 * description: "Sync from external program.",
10 * revision: "3"
11 * };
12 */
13
14export const myAdjustPointsFunction = webMethod(Permissions.Anyone, async (accountId, options) => {
15 try {
16 const updatedAccount = await accounts.adjustPoints(accountId, options);
17
18 const updatedBalance = updatedAccount.account.points.balance;
19 const transactionId = updatedAccount.account.latestTransaction._id;
20
21 console.log('Success! New account balance is: ', updatedBalance, ' The ID for this transaction is: ', transactionId);
22
23 return updatedAccount;
24 } catch (error) {
25 console.error(error);
26 }
27});
28
29/* Promise resolves to:
30 * {
31 * "account": {
32 * "_id": "1ab8f49c-a329-4ddc-a31d-814afbb3b565",
33 * "contactId": "3128dc64-74fc-442f-aa32-e8e871dad141",
34 * "memberId": "3128dc64-74fc-442f-aa32-e8e871dad141",
35 * "points": {
36 * "balance": 715,
37 * "earned": 0,
38 * "adjusted": 715,
39 * "redeemed": 0
40 * },
41 * "latestTransaction": {
42 * "_id": "da9096b4-a7fe-41a0-bf3b-05c22e3102fb",
43 * "amount": 715,
44 * "type": "ADJUST",
45 * "description": "Sync from external program.",
46 * "_createdDate": "2023-01-17T12:04:49.171Z",
47 * "appId": "553c79f3-5625-4f38-b14b-ef7c0d1e87df"
48 * },
49 * "rewardAvailable": false,
50 * "_createdDate": "2022-11-28T11:57:30.722Z",
51 * "_updatedDate": "2023-01-17T12:04:49.620Z",
52 * "lastActivityDate": "2023-01-17T12:04:49.619Z",
53 * "revision": "2",
54 * "tier": {
55 * "_id": "05e9d924-54c4-4540-94ef-8edd1e303611",
56 * "_updatedDate": "2023-01-17T12:04:49.619Z",
57 * "points": 715
58 * }
59 * }
60 * }
61 */
62
Get a loyalty account's latest revision, then give points to the account

First, retrieve the account using getAccount(). Then, extract the revision and pass it to options argument for the adjustPoints() function.

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { accounts } from 'wix-loyalty.v2';
3import * as wixAuth from 'wix-auth';
4
5// Sample accountId value: "1ab8f49c-a329-4ddc-a31d-814afbb3b565".
6
7/* Sample options value:
8 * {
9 * "amount": 50,
10 * "description": "Shared on social media."
11 * }
12 */
13
14export const myGetRevisionAndAdjustPointsFunction = webMethod(Permissions.Anyone, async (accountId, options) => {
15 const elevatedGetLoyaltyAccount = wixAuth.elevate(accounts.getAccount);
16 const retrievedLoyaltyAccount = await elevatedGetLoyaltyAccount(accountId);
17 const currentRevision = retrievedLoyaltyAccount.account.revision;
18
19 options.revision = currentRevision;
20
21 const elevatedAdjustPoints = wixAuth.elevate(accounts.adjustPoints);
22
23 try {
24 const updatedAccount = await elevatedAdjustPoints(accountId, options);
25
26 const updatedBalance = updatedAccount.account.points.balance;
27 const transactionId = updatedAccount.account.latestTransaction._id;
28
29 console.log('Success! New account balance is: ', updatedBalance, '. This ID for this transaction is: ', transactionId);
30
31 return updatedAccount;
32 } catch (error) {
33 console.error(error);
34 }
35});
36
37/* Promise resolves to:
38 * {
39 * "account": {
40 * "_id": "1ab8f49c-a329-4ddc-a31d-814afbb3b565",
41 * "contactId": "3128dc64-74fc-442f-aa32-e8e871dad141",
42 * "memberId": "3128dc64-74fc-442f-aa32-e8e871dad141",
43 * "points": {
44 * "balance": 295,
45 * "earned": 45,
46 * "adjusted": 250,
47 * "redeemed": 0
48 * },
49 * "latestTransaction": {
50 * "_id": "060e672a-d86b-4761-b587-1e97a34fd2f6",
51 * "amount": 50,
52 * "type": "GIVE",
53 * "description": "",
54 * "_createdDate": "2023-01-19T12:03:16.752Z",
55 * "appId": "553c79f3-5625-4f38-b14b-ef7c0d1e87df"
56 * },
57 * "rewardAvailable": true,
58 * "_createdDate": "2022-11-28T11:57:30.722Z",
59 * "_updatedDate": "2023-01-19T12:03:16.946Z",
60 * "lastActivityDate": "2023-01-19T12:03:16.945Z",
61 * "revision": "19",
62 * "tier": {
63 * "_id": "65fdf385-37b9-42e8-81c8-2e5fafe446f0",
64 * "_updatedDate": "2023-01-19T12:03:16.945Z",
65 * "points": 295
66 * }
67 * }
68 * }
69 */
70