Search...
getAccount( )
Developer Preview
Retrieves an account using the loyalty account ID.
Description
The getAccount()
function returns a Promise that resolves to the specified loyalty account when it is retrieved.
You can also get an account using a secondary ID, such as a contact ID or a member ID with the getAccountBySecondaryId()
function.
Note: Only visitors with Manage Loyalty permissions can retrieve 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 getAccount(_id: string): Promise<GetAccountResponse>
getAccount Parameters
NAME
TYPE
DESCRIPTION
_id
string
ID of the account to retrieve.
Returns
Return Type:
Promise<
GetAccountResponse
>NAME
TYPE
DESCRIPTION
account
LoyaltyAccount
Retrieved loyalty account.
Was this helpful?
Get a loyalty account (dashboard page code)
Copy Code
1import { accounts } from 'wix-loyalty.v2';23// Sample accountId value: 'e6f39a5b-a6d0-4556-b889-0cf09d8a84f7'45export async function myGetLoyaltyAccountFunction() {6 try {7 const loyaltyAccount = await accounts.getAccount(accountId);89 const currentBalance = loyaltyAccount.account.points.balance;10 const canGetReward = loyaltyAccount.account.rewardAvailable;1112 console.log('Success! Current points balance for this account is: ', currentBalance, ' and there is a reward available: ', canGetReward);1314 return loyaltyAccount;15 } catch (error) {16 console.error(error);17 }18}1920/* Promise resolves to:21 * {22 * "account": {23 * "_id": "e6f39a5b-a6d0-4556-b889-0cf09d8a84f7",24 * "contactId": "88615e02-3e8a-4297-8939-5d0a432b322a",25 * "memberId": "a517751b-a1ca-4423-8d91-aaf8f5b34215",26 * "points": {27 * "balance": 15,28 * "earned": 10,29 * "redeemed": 0,30 * "adjusted": 531 * },32 * "latestTransaction": {33 * "_id": "262c8eb0-123e-4117-9fe6-4973a3551688",34 * "amount": 5,35 * "type": "ADJUST",36 * "description": "",37 * "_createdDate": "2021-12-07T07:30:23.749Z",38 * "appId": "553c79f3-5625-4f38-b14b-ef7c0d1e87df",39 * "idempotencyKey": "f33ce6re-cy18-445e-8761-23d9471b8b96"40 * },41 * "rewardAvailable": true,42 * "_createdDate": "2021-12-06T14:33:19.114Z",43 * "_updatedDate": "2021-12-07T07:30:23.749Z",44 * "revision": "4"45 * }46 * }47 */48
Get a loyalty account (export from backend code)
Copy Code
1import { Permissions, webMethod } from 'wix-web-module';2import { accounts } from 'wix-loyalty.v2';34// Sample accountId value: 'e6f39a5b-a6d0-4556-b889-0cf09d8a84f7'56export const myGetLoyaltyAccountFunction = webMethod(Permissions.Anyone, async () => {7 try {8 const loyaltyAccount = await accounts.getAccount(accountId);910 const currentBalance = loyaltyAccount.account.points.balance;11 const canGetReward = loyaltyAccount.account.rewardAvailable;1213 console.log('Success! Current points balance for this account is: ', currentBalance, ' and there is a reward available: ', canGetReward);1415 return loyaltyAccount;16 } catch (error) {17 console.error(error);18 }19});2021/* Promise resolves to:22 * {23 * "account": {24 * "_id": "e6f39a5b-a6d0-4556-b889-0cf09d8a84f7",25 * "contactId": "88615e02-3e8a-4297-8939-5d0a432b322a",26 * "memberId": "a517751b-a1ca-4423-8d91-aaf8f5b34215",27 * "points": {28 * "balance": 15,29 * "earned": 10,30 * "redeemed": 0,31 * "adjusted": 532 * },33 * "latestTransaction": {34 * "_id": "262c8eb0-123e-4117-9fe6-4973a3551688",35 * "amount": 5,36 * "type": "ADJUST",37 * "description": "",38 * "_createdDate": "2021-12-07T07:30:23.749Z",39 * "appId": "553c79f3-5625-4f38-b14b-ef7c0d1e87df",40 * "idempotencyKey": "f33ce6re-cy18-445e-8761-23d9471b8b96"41 * },42 * "rewardAvailable": true,43 * "_createdDate": "2021-12-06T14:33:19.114Z",44 * "_updatedDate": "2021-12-07T07:30:23.749Z",45 * "revision": "4"46 * }47 * }48 */49