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

Copy Code
1import { accounts } from 'wix-loyalty.v2';
2
3// Sample accountId value: 'e6f39a5b-a6d0-4556-b889-0cf09d8a84f7'
4
5export async function myGetLoyaltyAccountFunction() {
6 try {
7 const loyaltyAccount = await accounts.getAccount(accountId);
8
9 const currentBalance = loyaltyAccount.account.points.balance;
10 const canGetReward = loyaltyAccount.account.rewardAvailable;
11
12 console.log('Success! Current points balance for this account is: ', currentBalance, ' and there is a reward available: ', canGetReward);
13
14 return loyaltyAccount;
15 } catch (error) {
16 console.error(error);
17 }
18}
19
20/* 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": 5
31 * },
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