adjustPoints( )
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 transactiontype
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.
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
Loyalty account ID.
Options to use when adjusting points.
Returns
Return Type:
NAME
TYPE
DESCRIPTION
Adjusted loyalty account.
Was this helpful?
1import { accounts } from 'wix-loyalty.v2';23// Sample accountId value: "1ab8f49c-a329-4ddc-a31d-814afbb3b565";45/* Sample options values:6 * {7 * balance: 715,8 * description: "Sync from external program.",9 * revision: "3"10 * };11 */1213export async function myAdjustPointsFunction(accountId, options) {14 try {15 const updatedAccount = await accounts.adjustPoints(accountId, options);1617 const updatedBalance = updatedAccount.account.points.balance;18 const transactionId = updatedAccount.account.latestTransaction._id;1920 console.log('Success! New account balance is: ', updatedBalance, ' The ID for this transaction is: ', transactionId);2122 return updatedAccount;23 } catch (error) {24 console.error(error);25 }26}2728/* 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": 039 * },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": 71557 * }58 * }59 * }60 */61
First, retrieve the account using getAccount()
. Then, extract the revision
and pass it to options
argument for the adjustPoints()
function.
1import { accounts } from 'wix-loyalty.v2';2import * as wixAuth from 'wix-auth';34// Sample accountId value: "1ab8f49c-a329-4ddc-a31d-814afbb3b565".56/* Sample options value:7 * {8 * "amount": 50,9 * "description": "Shared on social media."10 * }11 */1213export async function myGetRevisionAndAdjustPointsFunction(accountId, options) {1415 // Get the current revision of this loyalty account.16 const elevatedGetLoyaltyAccount = wixAuth.elevate(accounts.getAccount);17 const retrievedLoyaltyAccount = await elevatedGetLoyaltyAccount(accountId);18 const currentRevision = retrievedLoyaltyAccount.account.revision1920 // Update your options parameters for the latest revision21 options.revision = currentRevision2223 // Now call the `adjustPoints()` function.24 const elevatedAdjustPoints = wixAuth.elevate(accounts.adjustPoints);2526 try {27 const updatedAccount = await elevatedAdjustPoints(accountId, options);2829 const updatedBalance = updatedAccount.account.points.balance;30 const transactionId = updatedAccount.account.latestTransaction._id;3132 console.log('Success! New account balance is: ', updatedBalance, '. This ID for this transaction is: ', transactionId);3334 return updatedAccount;35 } catch (error) {36 console.error(error);37 }38}3940/* Promise resolves to:41 * {42 * "account": {43 * "_id": "1ab8f49c-a329-4ddc-a31d-814afbb3b565",44 * "contactId": "3128dc64-74fc-442f-aa32-e8e871dad141",45 * "memberId": "3128dc64-74fc-442f-aa32-e8e871dad141",46 * "points": {47 * "balance": 295,48 * "earned": 45,49 * "adjusted": 250,50 * "redeemed": 051 * },52 * "latestTransaction": {53 * "_id": "060e672a-d86b-4761-b587-1e97a34fd2f6",54 * "amount": 50,55 * "type": "GIVE",56 * "description": "",57 * "_createdDate": "2023-01-19T12:03:16.752Z",58 * "appId": "553c79f3-5625-4f38-b14b-ef7c0d1e87df"59 * },60 * "rewardAvailable": true,61 * "_createdDate": "2022-11-28T11:57:30.722Z",62 * "_updatedDate": "2023-01-19T12:03:16.946Z",63 * "lastActivityDate": "2023-01-19T12:03:16.945Z",64 * "revision": "19",65 * "tier": {66 * "_id": "65fdf385-37b9-42e8-81c8-2e5fafe446f0",67 * "_updatedDate": "2023-01-19T12:03:16.945Z",68 * "points": 29569 * }70 * }71 * }72 */73