Search.../

listAccounts( )

Developer Preview

Retrieves a list of loyalty accounts, given the provided filters.

Description

The listAccounts() function returns a Promise that resolves to a list of loyalty accounts.

You can retrieve selected loyalty accounts with an array of contactIds or retrieve a list of all of a site's loyalty accounts with an empty request parameter. Use the cursorPaging parameters to limit how many items load at a time.

Note: Only visitors with Manage Loyalty permissions can retrieve loyalty accounts.

Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function listAccounts(options: ListAccountsOptions): Promise<ListAccountsResponse>

listAccounts Parameters

NAME
TYPE
DESCRIPTION
options
Optional
ListAccountsOptions

Options to use when retrieving a list of loyalty accounts.

Returns

Return Type:

Promise<
ListAccountsResponse
>
NAME
TYPE
DESCRIPTION
accounts
Array<
LoyaltyAccount
>

Retrieved loyalty accounts.

pagingMetadata
PagingMetadataV2

Details on the paged set of results returned.

Was this helpful?

Get a list of loyalty accounts, limited to 3 accounts

Copy Code
1import { accounts } from 'wix-loyalty.v2';
2
3/* Sample options value:
4 * {
5 * 'cursorPaging': {
6 * 'limit': 3
7 * }
8 * }
9 */
10
11export async function myListLoyaltyAccountsFunction() {
12 try {
13 const accountsList = await accounts.listAccounts(options);
14
15 const firstAccountId = accountsList.accounts[0]._id;
16 const firstAccountBalance = accountsList.accounts[0].points.balance;
17
18 console.log('Success! The ID and point balance for the first account in your list is: ', firstAccountId, ' and ', firstAccountBalance);
19
20 return accountsList;
21 } catch (error) {
22 console.error(error);
23 }
24}
25
26/* Promise resolves to:
27 * {
28 * "accounts": [
29 * {
30 * "_id": "dd0020ca-eef0-4ff1-a615-63ecdcdfcd28",
31 * "contactId": "8a71f711-f77b-43fe-9e3d-5c243f94b2bc",
32 * "points": {
33 * "balance": 700,
34 * "earned": 135,
35 * "adjusted": 565,
36 * "redeemed": 0
37 * },
38 * "latestTransaction": {
39 * "_id": "65ac9989-89cd-40bb-9bfa-52d3b1e2fae2",
40 * "amount": 50,
41 * "type": "EARN",
42 * "description": "Subscribed to newsletter.",
43 * "_createdDate": "2022-11-09T11:18:44.987Z",
44 * "appId": "553c79f3-5625-4f38-b14b-ef7c0d1e87df",
45 * "idempotencyKey": "fc3df3c1-36b2-4279-8be1-8e72a05a88c8"
46 * },
47 * "rewardAvailable": true,
48 * "_createdDate": "2022-11-08T22:52:44.758Z",
49 * "_updatedDate": "2022-11-09T11:18:45.037Z",
50 * "revision": "6",
51 * "tier": {
52 * "_updatedDate": "2022-11-09T11:18:45.037Z",
53 * "points": 700
54 * }
55 * },
56 * {
57 * "_id": "7b801cdf-e74c-42b7-ba57-a068a78ea6b5",
58 * "contactId": "6f158e70-26f6-4fce-80a8-1d57e6791c34",
59 * "points": {
60 * "balance": 125,
61 * "earned": 125,
62 * "adjusted": 0,
63 * "redeemed": 0
64 * },
65 * "latestTransaction": {
66 * "_id": "93f31476-f3cf-4440-9933-aaca6e61e15b",
67 * "amount": 125,
68 * "type": "EARN",
69 * "description": "",
70 * "_createdDate": "2022-11-09T06:41:48.450Z",
71 * "appId": "553c79f3-5625-4f38-b14b-ef7c0d1e87df",
72 * "idempotencyKey": "262c8eb0-123e-4117-9fe6-4973a3551688"
73 * },
74 * "rewardAvailable": true,
75 * "_createdDate": "2022-11-07T15:49:11.763Z",
76 * "_updatedDate": "2022-11-09T06:41:48.879Z",
77 * "revision": "3",
78 * "tier": {
79 * "_updatedDate": "2022-11-09T06:41:48.616Z",
80 * "points": 125
81 * }
82 * },
83 * {
84 * "_id": "f0411f1a-ad5a-4b80-94c2-34350cbf1af7",
85 * "contactId": "8a71f711-f77b-43fe-9e3d-5c243f94b2cd",
86 * "points": {
87 * "balance": 0,
88 * "earned": 0,
89 * "adjusted": 0,
90 * "redeemed": 0
91 * },
92 * "rewardAvailable": false,
93 * "_createdDate": "2022-11-09T06:44:48.159Z",
94 * "_updatedDate": "2022-11-09T06:44:48.159Z",
95 * "revision": "1"
96 * }
97 * ],
98 * "pagingMetadata": {
99 * "count": 3,
100 * "total": 4,
101 * "cursors": {
102 * "next": "4cdca1370d1419d1874c0eb639ef64804fa6d5de.Gh0KDnBvaW50cy5iYWxhbmNlEAEaCREAAAAAAAAAABorCgxfdXBkYXRlZERhdGUaGyoZChcKCiR0aW1lc3RhbXASCREA8HklskV4QiIkZjA0MTFmMWEtYWQ1YS00YjgwLTk0YzItMzQzNTBjYmYxYWY3"
103 * }
104 * }
105 * }
106 */
107
Get a list of specific loyalty accounts using their account IDs

Copy Code
1import { accounts } from 'wix-loyalty.v2';
2
3/* Sample options value:
4 * {
5 * contactIds: [
6 * '8a71f711-f77b-43fe-9e3d-5c243f94b2bc',
7 * '6f158e70-26f6-4fce-80a8-1d57e6791c34'
8 * ]
9 * }
10 */
11
12export async function myListLoyaltyAccountsFunction() {
13 try {
14 const accountsList = await accounts.listAccounts(contactIds);
15
16 const firstAccountId = accountsList.accounts[0]._id;
17 const firstAccountBalance = accountsList.accounts[0].points.balance;
18
19 console.log('Success! The ID and point balance for the first account in your list is: ', firstAccountId, 'and ', firstAccountBalance);
20
21 return accountsList;
22 } catch (error) {
23 console.error(error);
24 }
25}
26
27/* Promise resolves to:
28 * {
29 * "accounts": [
30 * {
31 * "_id": "dd0020ca-eef0-4ff1-a615-63ecdcdfcd28",
32 * "contactId": "8a71f711-f77b-43fe-9e3d-5c243f94b2bc",
33 * "points": {
34 * "balance": 700,
35 * "earned": 135,
36 * "adjusted": 565,
37 * "redeemed": 0
38 * },
39 * "latestTransaction": {
40 * "_id": "65ac9989-89cd-40bb-9bfa-52d3b1e2fae2",
41 * "amount": 50,
42 * "type": "EARN",
43 * "description": "Subscribed to newsletter.",
44 * "_createdDate": "2022-11-09T11:18:44.987Z",
45 * "appId": "553c79f3-5625-4f38-b14b-ef7c0d1e87df",
46 * "idempotencyKey": "fc3df3c1-36b2-4279-8be1-8e72a05a88c8"
47 * },
48 * "rewardAvailable": true,
49 * "_createdDate": "2022-11-08T22:52:44.758Z",
50 * "_updatedDate": "2022-11-09T11:18:45.037Z",
51 * "revision": "6",
52 * "tier": {
53 * "_updatedDate": "2022-11-09T11:18:45.037Z",
54 * "points": 700
55 * }
56 * },
57 * {
58 * "_id": "7b801cdf-e74c-42b7-ba57-a068a78ea6b5",
59 * "contactId": "6f158e70-26f6-4fce-80a8-1d57e6791c34",
60 * "points": {
61 * "balance": 125,
62 * "earned": 125,
63 * "adjusted": 0,
64 * "redeemed": 0
65 * },
66 * "latestTransaction": {
67 * "_id": "93f31476-f3cf-4440-9933-aaca6e61e15b",
68 * "amount": 125,
69 * "type": "EARN",
70 * "description": "",
71 * "_createdDate": "2022-11-09T06:41:48.450Z",
72 * "appId": "553c79f3-5625-4f38-b14b-ef7c0d1e87df",
73 * "idempotencyKey": "262c8eb0-123e-4117-9fe6-4973a3551688"
74 * },
75 * "rewardAvailable": true,
76 * "_createdDate": "2022-11-07T15:49:11.763Z",
77 * "_updatedDate": "2022-11-09T06:41:48.879Z",
78 * "revision": "3",
79 * "tier": {
80 * "_updatedDate": "2022-11-09T06:41:48.616Z",
81 * "points": 125
82 * }
83 * }
84 * ],
85 * "pagingMetadata": {
86 * "count": 2,
87 * "total": 2,
88 * "cursors": {}
89 * }
90 * }
91 */
92