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
contactId
string

Contact ID for a Wix site contact. See the Contacts API to learn more.

Returns

Return Type:

Promise<
CreateAccountResponse
>
NAME
TYPE
DESCRIPTION
account
LoyaltyAccount

Created loyalty account.

Was this helpful?

Create a loyalty account for a site contact (dashboard page code)

Copy Code
1import { accounts } from 'wix-loyalty.v2';
2
3// Sample contactId value: 'ff61204b-b19a-5cc8-823b-7eed8ae5fc28'
4
5export async function myCreateAccountFunction() {
6 try {
7 const newLoyaltyAccount = await accounts.createAccount(contactId);
8
9 const accountId = newLoyaltyAccount.account._id;
10
11 console.log('Success! The account ID for this new loyalty account is: ', accountId);
12
13 return newLoyaltyAccount;
14 } catch (error) {
15 console.error(error);
16 }
17}
18
19/* 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": 0
29 * },
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
Create a loyalty account for a site contact (export from backend code)

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { accounts } from 'wix-loyalty.v2';
3
4// Sample contactId value: 'ff61204b-b19a-5cc8-823b-7eed8ae5fc28'
5
6export const myCreateAccountFunction = webMethod(Permissions.Anyone, async () => {
7 try {
8 const newLoyaltyAccount = await accounts.createAccount(contactId);
9
10 const accountId = newLoyaltyAccount.account._id;
11
12 console.log('Success! The account ID for this new loyalty account is: ', accountId);
13
14 return newLoyaltyAccount;
15 } catch (error) {
16 console.error(error);
17 }
18});
19
20/* 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": 0
30 * },
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