createAccount( )
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.
This function requires elevated permissions to run. This function is not universal and runs only on the backend.
Authorization
Request
This endpoint does not take any parameters
Response Object
NAME
TYPE
DESCRIPTION
Created loyalty account.
Status/Error Codes
Was this helpful?
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
1import { Permissions, webMethod } from 'wix-web-module';2import { accounts } from 'wix-loyalty.v2';34// Sample contactId value: 'ff61204b-b19a-5cc8-823b-7eed8ae5fc28'56export const myCreateAccountFunction = webMethod(Permissions.Anyone, async () => {7 try {8 const newLoyaltyAccount = await accounts.createAccount(contactId);910 const accountId = newLoyaltyAccount.account._id;1112 console.log('Success! The account ID for this new loyalty account is: ', accountId);1314 return newLoyaltyAccount;15 } catch (error) {16 console.error(error);17 }18});1920/* Promise resolves to:21 * {22 * "account": {23 * "_id": "1e3f99cf-1e7f-4cba-8777-f081549f49cd",24 * "contactId": "ff61204b-b19a-5cc8-823b-7eed8ae5fc28",25 * "points": {26 * "balance": 0,27 * "earned": 0,28 * "adjusted": 0,29 * "redeemed": 030 * },31 * "rewardAvailable": false,32 * "_createdDate": "2022-11-09T12:49:25.408Z",33 * "_updatedDate": "2022-11-09T12:49:25.408Z",34 * "revision": "1"35 * }36 * }37 */38