Search...
createAccount( )
Developer Preview
Creates a loyalty account for one of a site's contacts.
Description
The createAccount()
function returns a Promise that resolves to the new loyalty account when it is created.
To create a new loyalty account, the customer must first be a site contact with a contact ID. See contacts to learn more about a site's contacts. The site must also have an active loyalty program before loyalty accounts can be created. See the activateLoyaltyProgram()
function to activate a site's loyalty program.
Note: Only visitors with Manage Loyalty permissions can create 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 createAccount(contactId: string): Promise<CreateAccountResponse>
createAccount Parameters
NAME
TYPE
DESCRIPTION
Returns
Return Type:
Promise<
CreateAccountResponse
>NAME
TYPE
DESCRIPTION
account
LoyaltyAccount
Created loyalty account.
Was this helpful?
Create a loyalty account for a site contact
Copy Code
1import { accounts } from 'wix-loyalty.v2';23// Sample contactId value: 'ff61204b-b19a-5cc8-823b-7eed8ae5fc28'45export async function myCreateAccountFunction() {6 try {7 const newLoyaltyAccount = await accounts.createAccount(contactId);89 const accountId = newLoyaltyAccount.account._id;1011 console.log('Success! The account ID for this new loyalty account is: ', accountId);1213 return newLoyaltyAccount;14 } catch (error) {15 console.error(error);16 }17}1819/* Promise resolves to:20 * {21 * "account": {22 * "_id": "1e3f99cf-1e7f-4cba-8777-f081549f49cd",23 * "contactId": "ff61204b-b19a-5cc8-823b-7eed8ae5fc28",24 * "points": {25 * "balance": 0,26 * "earned": 0,27 * "adjusted": 0,28 * "redeemed": 029 * },30 * "rewardAvailable": false,31 * "_createdDate": "2022-11-09T12:49:25.408Z",32 * "_updatedDate": "2022-11-09T12:49:25.408Z",33 * "revision": "1"34 * }35 * }36 */37