listAccounts( )
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.
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 to use when retrieving a list of loyalty accounts.
Returns
Return Type:
NAME
TYPE
DESCRIPTION
Retrieved loyalty accounts.
Details on the paged set of results returned.
Was this helpful?
1import { accounts } from 'wix-loyalty.v2';23/* Sample options value:4 * {5 * 'cursorPaging': {6 * 'limit': 37 * }8 * }9 */1011export async function myListLoyaltyAccountsFunction() {12 try {13 const accountsList = await accounts.listAccounts(options);1415 const firstAccountId = accountsList.accounts[0]._id;16 const firstAccountBalance = accountsList.accounts[0].points.balance;1718 console.log('Success! The ID and point balance for the first account in your list is: ', firstAccountId, ' and ', firstAccountBalance);1920 return accountsList;21 } catch (error) {22 console.error(error);23 }24}2526/* 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": 037 * },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": 70054 * }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": 064 * },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": 12581 * }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": 091 * },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
1import { Permissions, webMethod } from 'wix-web-module';2import { accounts } from 'wix-loyalty.v2';34/* Sample options value:5 * {6 * 'cursorPaging': {7 * 'limit': 38 * }9 * }10 */1112export const myListLoyaltyAccountsFunction = webMethod(Permissions.Anyone, async () => {13 try {14 const accountsList = await accounts.listAccounts(options);1516 const firstAccountId = accountsList.accounts[0]._id;17 const firstAccountBalance = accountsList.accounts[0].points.balance;1819 console.log('Success! The ID and point balance for the first account in your list is: ', firstAccountId, ' and ', firstAccountBalance);2021 return accountsList;22 } catch (error) {23 console.error(error);24 }25});2627/* 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": 038 * },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": 70055 * }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": 065 * },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": 12582 * }83 * },84 * {85 * "_id": "f0411f1a-ad5a-4b80-94c2-34350cbf1af7",86 * "contactId": "8a71f711-f77b-43fe-9e3d-5c243f94b2cd",87 * "points": {88 * "balance": 0,89 * "earned": 0,90 * "adjusted": 0,91 * "redeemed": 092 * },93 * "rewardAvailable": false,94 * "_createdDate": "2022-11-09T06:44:48.159Z",95 * "_updatedDate": "2022-11-09T06:44:48.159Z",96 * "revision": "1"97 * }98 * ],99 * "pagingMetadata": {100 * "count": 3,101 * "total": 4,102 * "cursors": {103 * "next": "4cdca1370d1419d1874c0eb639ef64804fa6d5de.Gh0KDnBvaW50cy5iYWxhbmNlEAEaCREAAAAAAAAAABorCgxfdXBkYXRlZERhdGUaGyoZChcKCiR0aW1lc3RhbXASCREA8HklskV4QiIkZjA0MTFmMWEtYWQ1YS00YjgwLTk0YzItMzQzNTBjYmYxYWY3"104 * }105 * }106 * }107 */108
1import { Permissions, webMethod } from 'wix-web-module';2import { accounts } from 'wix-loyalty.v2';34/* Sample options value:5 * {6 * contactIds: [7 * '8a71f711-f77b-43fe-9e3d-5c243f94b2bc',8 * '6f158e70-26f6-4fce-80a8-1d57e6791c34'9 * ]10 * }11 */1213export const myListLoyaltyAccountsFunction = webMethod(Permissions.Anyone, async () => {14 try {15 const accountsList = await accounts.listAccounts(contactIds);1617 const firstAccountId = accountsList.accounts[0]._id;18 const firstAccountBalance = accountsList.accounts[0].points.balance;1920 console.log('Success! The ID and point balance for the first account in your list is: ', firstAccountId, 'and ', firstAccountBalance);2122 return accountsList;23 } catch (error) {24 console.error(error);25 }26});2728/* Promise resolves to:29 * {30 * "accounts": [31 * {32 * "_id": "dd0020ca-eef0-4ff1-a615-63ecdcdfcd28",33 * "contactId": "8a71f711-f77b-43fe-9e3d-5c243f94b2bc",34 * "points": {35 * "balance": 700,36 * "earned": 135,37 * "adjusted": 565,38 * "redeemed": 039 * },40 * "latestTransaction": {41 * "_id": "65ac9989-89cd-40bb-9bfa-52d3b1e2fae2",42 * "amount": 50,43 * "type": "EARN",44 * "description": "Subscribed to newsletter.",45 * "_createdDate": "2022-11-09T11:18:44.987Z",46 * "appId": "553c79f3-5625-4f38-b14b-ef7c0d1e87df",47 * "idempotencyKey": "fc3df3c1-36b2-4279-8be1-8e72a05a88c8"48 * },49 * "rewardAvailable": true,50 * "_createdDate": "2022-11-08T22:52:44.758Z",51 * "_updatedDate": "2022-11-09T11:18:45.037Z",52 * "revision": "6",53 * "tier": {54 * "_updatedDate": "2022-11-09T11:18:45.037Z",55 * "points": 70056 * }57 * },58 * {59 * "_id": "7b801cdf-e74c-42b7-ba57-a068a78ea6b5",60 * "contactId": "6f158e70-26f6-4fce-80a8-1d57e6791c34",61 * "points": {62 * "balance": 125,63 * "earned": 125,64 * "adjusted": 0,65 * "redeemed": 066 * },67 * "latestTransaction": {68 * "_id": "93f31476-f3cf-4440-9933-aaca6e61e15b",69 * "amount": 125,70 * "type": "EARN",71 * "description": "",72 * "_createdDate": "2022-11-09T06:41:48.450Z",73 * "appId": "553c79f3-5625-4f38-b14b-ef7c0d1e87df",74 * "idempotencyKey": "262c8eb0-123e-4117-9fe6-4973a3551688"75 * },76 * "rewardAvailable": true,77 * "_createdDate": "2022-11-07T15:49:11.763Z",78 * "_updatedDate": "2022-11-09T06:41:48.879Z",79 * "revision": "3",80 * "tier": {81 * "_updatedDate": "2022-11-09T06:41:48.616Z",82 * "points": 12583 * }84 * }85 * ],86 * "pagingMetadata": {87 * "count": 2,88 * "total": 2,89 * "cursors": {}90 * }91 * }92 */93