Retrieves the loyalty account of the specified site contact or member.
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.
This function requires elevated permissions and runs only on the backend and on dashboard pages.
function getAccountBySecondaryId(
options: GetAccountBySecondaryIdOptions,
): Promise<GetAccountBySecondaryIdResponse>;
ID of the customer to retrieve loyalty account for.
import { accounts } from "wix-loyalty.v2";
/* Sample options value:
* {
* contactId: '8a71f711-f77b-43fe-9e3d-5c243f94b2bc'
* }
*/
export async function myGetAccountByContactIdFunction() {
try {
const loyaltyAccount = await accounts.getAccountBySecondaryId(options);
const accountId = loyaltyAccount.account._id;
const currentRevision = loyaltyAccount.account.revision;
console.log(
"Success! This site contact's loyalty account ID is: ",
accountId,
);
return loyaltyAccount;
} catch (error) {
console.error(error);
}
}
/* Promise resolves to:
* {
* "account": {
* "_id": "dd0020ca-eef0-4ff1-a615-63ecdcdfcd28",
* "contactId": "8a71f711-f77b-43fe-9e3d-5c243f94b2bc",
* "points": {
* "balance": 700,
* "earned": 135,
* "adjusted": 565,
* "redeemed": 0
* },
* "rewardAvailable": true,
* "_createdDate": "2022-11-08T22:52:44.758Z",
* "_updatedDate": "2022-11-09T11:18:45.037Z",
* "revision": "6",
* "tier": {
* "_updatedDate": "2022-11-09T11:18:45.037Z",
* "points": 700
* }
* }
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.