getAccountBySecondaryId( )


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.

Authentication
  • When developing websites or building an app with Blocks, this method may require elevated permissions, depending on the identity of the user calling it and the calling user’s permissions.
  • When building apps without Blocks or for headless projects, you can only call this method directly when authenticated as a Wix app or Wix user identity. When authenticated as a different identity, you can call this method using elevation.
  • Elevation permits users to call methods they typically cannot access. Therefore, you should only use it intentionally and securely.
Permissions
Manage Loyalty
Read Loyalty
Manage Restaurants - all permissions
Learn more about app permissions.
Method Declaration
Copy
function getAccountBySecondaryId(
  options: GetAccountBySecondaryIdOptions,
): Promise<GetAccountBySecondaryIdResponse>;
Method Parameters
optionsGetAccountBySecondaryIdOptions

ID of the customer to retrieve loyalty account for.

Returns
Return Type:Promise<GetAccountBySecondaryIdResponse>
JavaScript
import { accounts } from "@wix/loyalty"; /* Sample options value: * { * contactId: '8a71f711-f77b-43fe-9e3d-5c243f94b2bc' * } */ const options = { contactId: "8a71f711-f77b-43fe-9e3d-5c243f94b2bc" }; // Define options 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 * } * } * } */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?