Retrieves an account using the loyalty account ID.
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.
This function requires elevated permissions and runs only on the backend and on dashboard pages.
function getAccount(_id: string): Promise<LoyaltyAccount>;
ID of the account to retrieve.
import { accounts } from "wix-loyalty.v2";
// Sample accountId value: 'e6f39a5b-a6d0-4556-b889-0cf09d8a84f7'
export async function myGetLoyaltyAccountFunction() {
try {
const loyaltyAccount = await accounts.getAccount(accountId);
const currentBalance = loyaltyAccount.account.points.balance;
const canGetReward = loyaltyAccount.account.rewardAvailable;
console.log(
"Success! Current points balance for this account is: ",
currentBalance,
" and there is a reward available: ",
canGetReward,
);
return loyaltyAccount;
} catch (error) {
console.error(error);
}
}
/* Promise resolves to:
* {
* "account": {
* "_id": "e6f39a5b-a6d0-4556-b889-0cf09d8a84f7",
* "contactId": "88615e02-3e8a-4297-8939-5d0a432b322a",
* "memberId": "a517751b-a1ca-4423-8d91-aaf8f5b34215",
* "points": {
* "balance": 15,
* "earned": 10,
* "redeemed": 0,
* "adjusted": 5
* },
* "rewardAvailable": true,
* "_createdDate": "2021-12-06T14:33:19.114Z",
* "_updatedDate": "2021-12-07T07:30:23.749Z",
* "revision": "4"
* }
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.