Search.../

getAccountBySecondaryId( )

Developer Preview

Retrieves the loyalty account of the specified site contact or member.

Description

The getAccountBySecondaryId() function returns a Promise that resolves to the specified loyalty account when it is retrieved.

This function gets a loyalty account using either a customer's contact ID or member ID. You can also get an account using the loyalty account ID with the getAccount() 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 getAccountBySecondaryId(options: GetAccountBySecondaryIdOptions): Promise<GetAccountBySecondaryIdResponse>

getAccountBySecondaryId Parameters

NAME
TYPE
DESCRIPTION
options
Optional
GetAccountBySecondaryIdOptions

ID of the customer to retrieve loyalty account for.

Returns

Return Type:

Promise<
GetAccountBySecondaryIdResponse
>
NAME
TYPE
DESCRIPTION
account
LoyaltyAccount

Retrieved loyalty account.

Was this helpful?

Get a loyalty account using a contact ID

Copy Code
1import { accounts } from 'wix-loyalty.v2';
2
3/* Sample options value:
4 * {
5 * contactId: '8a71f711-f77b-43fe-9e3d-5c243f94b2bc'
6 * }
7 */
8
9export async function myGetAccountByContactIdFunction() {
10 try {
11 const loyaltyAccount = await accounts.getAccountBySecondaryId(options);
12
13 const accountId = loyaltyAccount.account._id;
14 const currentRevision = loyaltyAccount.account.revision;
15
16 console.log("Success! This site contact's loyalty account ID is: ", accountId);
17
18 return loyaltyAccount;
19 } catch (error) {
20 console.error(error);
21 }
22}
23
24/* Promise resolves to:
25 * {
26 * "account": {
27 * "_id": "dd0020ca-eef0-4ff1-a615-63ecdcdfcd28",
28 * "contactId": "8a71f711-f77b-43fe-9e3d-5c243f94b2bc",
29 * "points": {
30 * "balance": 700,
31 * "earned": 135,
32 * "adjusted": 565,
33 * "redeemed": 0
34 * },
35 * "latestTransaction": {
36 * "_id": "65ac9989-89cd-40bb-9bfa-52d3b1e2fae2",
37 * "amount": 50,
38 * "type": "EARN",
39 * "description": "Signed up for newsletter",
40 * "_createdDate": "2022-11-09T11:18:44.987Z",
41 * "appId": "553c79f3-5625-4f38-b14b-ef7c0d1e87df",
42 * "idempotencyKey": "b494fca4-3fec-40e9-b7a0-43e51b0b5057"
43 * },
44 * "rewardAvailable": true,
45 * "_createdDate": "2022-11-08T22:52:44.758Z",
46 * "_updatedDate": "2022-11-09T11:18:45.037Z",
47 * "revision": "6",
48 * "tier": {
49 * "_updatedDate": "2022-11-09T11:18:45.037Z",
50 * "points": 700
51 * }
52 * }
53 * }
54 */
55