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