> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# QueryLoyaltyAccounts

# Package: accounts

# Namespace: LoyaltyAccounts

# Method link: https://dev.wix.com/docs/api-reference/crm/loyalty-program/accounts/accounts/query-loyalty-accounts?apiView=SDK.md

## Permission Scopes:
Read Loyalty: SCOPE.DC-LOYALTY.READ-LOYALTY

## Introduction

Retrieves a list of loyalty accounts, given the provided paging, filtering, and sorting.
Query Loyalty Accounts runs with these defaults, which you can override:
- `createdDate` is sorted in `ASC` order
- `paging.limit` is `100`
- `paging.offset` is `0`
To learn about working with _Query_ methods, see [API Query Language](https://dev.wix.com/docs/rest/articles/get-started/api-query-language.md).

---

## REST API

### Schema

```
 Method: queryLoyaltyAccounts
 Description: Retrieves a list of loyalty accounts, given the provided paging, filtering, and sorting. Query Loyalty Accounts runs with these defaults, which you can override: - `createdDate` is sorted in `ASC` order - `paging.limit` is `100` - `paging.offset` is `0` To learn about working with _Query_ methods, see [API Query Language](https://dev.wix.com/docs/rest/articles/get-started/api-query-language.md).
 URL: https://www.wixapis.com/loyalty-accounts/v1/accounts/query
 Method: POST
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  query
 Method parameters: 
   param name: query | type: CursorQuery   | required: true 
     - name: cursorPaging | type: CursorPaging | description: Cursor paging options.  Learn more about [cursor paging](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md#cursor-paging).  
        - name: limit | type: integer | description: Maximum number of items to return in the results.  | validation: minimum 0, maximum 100, format int32
        - name: cursor | type: string | description: Pointer to the next or previous page in the list of results.  Pass the relevant cursor token from the `pagingMetadata` object in the previous call's response. Not relevant for the first request.  | validation: maxLength 16000
        - name: filter | type: object | description: Filter object.  Learn more about [filtering](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md#filters).  
        - name: sort | type: array<Sorting> | description: Sort object.  Learn more about [sorting](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md#sorting).  | validation: maxItems 5
           - name: fieldName | type: string | description: Name of the field to sort by.  | validation: maxLength 512
           - name: order | type: SortOrder | description: Sort order.  
                 - enum: ASC, DESC
           - name: origin | type: AddressLocation | description: Origin point for geo-distance sorting on a GEO field results are ordered by distance from this point (ASC = nearest first, DESC = farthest first).  
              - name: latitude | type: number | description: Address latitude.  | validation: format double
              - name: longitude | type: number | description: Address longitude.  | validation: format double
 Query fields:
   - field: id | operators: $eq, $ne, $in, $exists, $gt, $gte, $lt, $lte, $startsWith | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: contactId | operators: $eq, $ne, $in, $exists, $gt, $gte, $lt, $lte, $startsWith | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: memberId | operators: $eq, $ne, $in, $exists, $gt, $gte, $lt, $lte, $startsWith | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: points.balance | operators: $eq, $ne, $in, $exists, $gt, $gte, $lt, $lte | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: points.earned | operators: $eq, $ne, $in, $exists, $gt, $gte, $lt, $lte | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: points.adjusted | operators: $eq, $ne, $in, $exists, $gt, $gte, $lt, $lte | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: points.redeemed | operators: $eq, $ne, $in, $exists, $gt, $gte, $lt, $lte | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: points.expired | operators: $eq, $ne, $in, $exists, $gt, $gte, $lt, $lte | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: createdDate | operators: $eq, $ne, $in, $exists, $gt, $gte, $lt, $lte | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: lastActivityDate | operators: $eq, $ne, $in, $exists, $gt, $gte, $lt, $lte | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: tier.id | operators: $eq, $ne, $in, $exists, $gt, $gte, $lt, $lte, $startsWith | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: pointsExpiration.expirationDate | operators: $eq, $ne, $in, $exists, $gt, $gte, $lt, $lte | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: pointsExpiration.expiringPointsAmount | operators: $eq, $ne, $in, $exists, $gt, $gte, $lt, $lte | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
 Return type: QueryLoyaltyAccountsResponse
  - name: loyaltyAccounts | type: array<LoyaltyAccount> | description: Retrieved loyalty accounts.  
     - name: id | type: string | description: Account GUID.  | read-only: true | validation: format GUID
     - name: contactId | type: string | description: Account owner's contact GUID. See the Contacts API to learn more about a site's contacts.  | read-only: true | validation: format GUID
     - name: memberId | type: string | description: Member GUID of the account owner. See the Members API to learn more about a site's members.  | read-only: true | validation: format GUID
     - name: points | type: Points | description: Details of the account's point totals.  | read-only: true 
        - name: balance | type: integer | description: Current points balance.  Equal to the sum of `earned` and `adjusted` points, minus `redeemed` points.  | read-only: true | validation: minimum 0
        - name: earned | type: integer | description: Total earned points.  | read-only: true | validation: minimum 0
        - name: adjusted | type: integer | description: Total adjusted points.  | read-only: true | validation: minimum 0
        - name: redeemed | type: integer | description: Total redeemed points.  | read-only: true | validation: minimum 0
        - name: expired | type: integer | description: Total expired points.  | read-only: true | validation: minimum 0
     - name: rewardAvailable | type: boolean | description: Whether the account has enough points in `points.balance` to redeem for a reward.  | read-only: true 
     - name: createdDate | type: string | description: Date and time the account was created.  | read-only: true | validation: format date-time
     - name: updatedDate | type: string | description: Date and time the account was last updated.  | read-only: true | validation: format date-time
     - name: lastActivityDate | type: string | description: Date and time of the account's last activity.  | read-only: true | validation: format date-time
     - name: revision | type: number | description: Revision number, which increments by 1 each time the loyalty account is updated.  To prevent conflicting changes, the current `revision` must be passed when updating the loyalty account.  Ignored when creating an account.  
     - name: tier | type: Tier | description: Tier information.  See the Tiers API for more information.  | read-only: true 
        - name: id | type: string | description: Tier GUID.  This field will not be returned if the account belongs to the base tier.  | read-only: true | validation: format GUID
        - name: updatedDate | type: string | description: Date and time the tier information was last recalculated.  | read-only: true | validation: format date-time
        - name: points | type: integer | description: Points earned and adjusted over the tier's current rolling window.  | read-only: true | validation: minimum 0
     - name: contact | type: Contact | description: Contact information.  | read-only: true 
        - name: id | type: string | description: Contact GUID.  | read-only: true | validation: format GUID
        - name: name | type: string | description: Contact's first and last name.  | read-only: true 
        - name: picture | type: Image | description: Contact's profile picture.  | read-only: true 
           - name: id | type: string | description: WixMedia image GUID.  
           - name: url | type: string | description: Image URL.  
           - name: height | type: integer | description: Original image height.  | read-only: true 
           - name: width | type: integer | description: Original image width.  | read-only: true 
        - name: email | type: string | description: Contact's email address.  | read-only: true | validation: format EMAIL
        - name: displayName | type: string | description: Contact's first and last name. If no name is provided, uses contact's email.  | read-only: true 
     - name: pointsExpiration | type: PointsExpiration | description: Points expiration information.  | read-only: true 
        - name: expirationDate | type: string | description: Date and time at which points are expiring.  | read-only: true | validation: format date-time
        - name: expiringPointsAmount | type: integer | description: Amount of points that are going to expire at that date.  | read-only: true 
  - name: pagingMetadata | type: CursorPagingMetadata | description: Paging metadata  
     - name: count | type: integer | description: Number of items returned in current page.  | validation: format int32
     - name: cursors | type: Cursors | description: Cursor strings that point to the next page, previous page, or both.  
        - name: next | type: string | description: Cursor string pointing to the next page in the list of results.  | validation: maxLength 16000
        - name: prev | type: string | description: Cursor pointing to the previous page in the list of results.  | validation: maxLength 16000
     - name: hasNext | type: boolean | description: Whether there are more pages to retrieve following the current page.  + `true`: Another page of results can be retrieved. + `false`: This is the last page.  


```

### Examples

### Query Accounts by ID
```curl
curl -X POST \
  'https://www.wixapis.com/loyalty-accounts/v1/accounts/query' \
  -H 'Authorization: <AUTH>'
  -H 'Content-Type: application/json' \
  -d '{
        "query": {
          "filter": {
            "id": {
              "$eq": "e6f39a5b-a6d0-4556-b889-0cf09d8a84f7"
            }
          }
        }
    }'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.loyalty.accounts.queryLoyaltyAccounts(query)
 Description: Retrieves a list of loyalty accounts, given the provided paging, filtering, and sorting. Query Loyalty Accounts runs with these defaults, which you can override: - `createdDate` is sorted in `ASC` order - `paging.limit` is `100` - `paging.offset` is `0` To learn about working with _Query_ methods, see [API Query Language](https://dev.wix.com/docs/rest/articles/get-started/api-query-language.md).
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  query
 Method parameters: 
   param name: query | type: AccountQuery   | required: true 
     - name: cursorPaging | type: CursorPaging | description: Cursor paging options.  Learn more about [cursor paging](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md#cursor-paging).  
        - name: limit | type: integer | description: Maximum number of items to return in the results.  | validation: minimum 0, maximum 100, format int32
        - name: cursor | type: string | description: Pointer to the next or previous page in the list of results.  Pass the relevant cursor token from the `pagingMetadata` object in the previous call's response. Not relevant for the first request.  | validation: maxLength 16000
        - name: filter | type: object | description: Filter object.  Learn more about [filtering](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md#filters).  
        - name: sort | type: array<Sorting> | description: Sort object.  Learn more about [sorting](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md#sorting).  | validation: maxItems 5
           - name: fieldName | type: string | description: Name of the field to sort by.  | validation: maxLength 512
           - name: order | type: SortOrder | description: Sort order.  
                 - enum: ASC, DESC
           - name: origin | type: AddressLocation | description: Origin point for geo-distance sorting on a GEO field results are ordered by distance from this point (ASC = nearest first, DESC = farthest first).  
              - name: latitude | type: number | description: Address latitude.  
              - name: longitude | type: number | description: Address longitude.  
 Query fields:
   - field: _id | operators: $eq, $ne, $in, $exists, $gt, $gte, $lt, $lte, $startsWith | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: contactId | operators: $eq, $ne, $in, $exists, $gt, $gte, $lt, $lte, $startsWith | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: memberId | operators: $eq, $ne, $in, $exists, $gt, $gte, $lt, $lte, $startsWith | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: points.balance | operators: $eq, $ne, $in, $exists, $gt, $gte, $lt, $lte | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: points.earned | operators: $eq, $ne, $in, $exists, $gt, $gte, $lt, $lte | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: points.adjusted | operators: $eq, $ne, $in, $exists, $gt, $gte, $lt, $lte | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: points.redeemed | operators: $eq, $ne, $in, $exists, $gt, $gte, $lt, $lte | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: points.expired | operators: $eq, $ne, $in, $exists, $gt, $gte, $lt, $lte | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: _createdDate | operators: $eq, $ne, $in, $exists, $gt, $gte, $lt, $lte | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: lastActivityDate | operators: $eq, $ne, $in, $exists, $gt, $gte, $lt, $lte | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: tier._id | operators: $eq, $ne, $in, $exists, $gt, $gte, $lt, $lte, $startsWith | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: pointsExpiration.expirationDate | operators: $eq, $ne, $in, $exists, $gt, $gte, $lt, $lte | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: pointsExpiration.expiringPointsAmount | operators: $eq, $ne, $in, $exists, $gt, $gte, $lt, $lte | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
 Return type: PROMISE<QueryLoyaltyAccountsResponse>
  - name: loyaltyAccounts | type: array<LoyaltyAccount> | description: Retrieved loyalty accounts.  
     - name: _id | type: string | description: Account GUID.  | read-only: true | validation: format GUID
     - name: contactId | type: string | description: Account owner's contact GUID. See the Contacts API to learn more about a site's contacts.  | read-only: true | validation: format GUID
     - name: memberId | type: string | description: Member GUID of the account owner. See the Members API to learn more about a site's members.  | read-only: true | validation: format GUID
     - name: points | type: Points | description: Details of the account's point totals.  | read-only: true 
        - name: balance | type: integer | description: Current points balance.  Equal to the sum of `earned` and `adjusted` points, minus `redeemed` points.  | read-only: true | validation: minimum 0
        - name: earned | type: integer | description: Total earned points.  | read-only: true | validation: minimum 0
        - name: adjusted | type: integer | description: Total adjusted points.  | read-only: true | validation: minimum 0
        - name: redeemed | type: integer | description: Total redeemed points.  | read-only: true | validation: minimum 0
        - name: expired | type: integer | description: Total expired points.  | read-only: true | validation: minimum 0
     - name: rewardAvailable | type: boolean | description: Whether the account has enough points in `points.balance` to redeem for a reward.  | read-only: true 
     - name: _createdDate | type: Date | description: Date and time the account was created.  | read-only: true 
     - name: _updatedDate | type: Date | description: Date and time the account was last updated.  | read-only: true 
     - name: lastActivityDate | type: Date | description: Date and time of the account's last activity.  | read-only: true 
     - name: revision | type: number | description: Revision number, which increments by 1 each time the loyalty account is updated.  To prevent conflicting changes, the current `revision` must be passed when updating the loyalty account.  Ignored when creating an account.  
     - name: tier | type: Tier | description: Tier information.  See the Tiers API for more information.  | read-only: true 
        - name: _id | type: string | description: Tier GUID.  This field will not be returned if the account belongs to the base tier.  | read-only: true | validation: format GUID
        - name: _updatedDate | type: Date | description: Date and time the tier information was last recalculated.  | read-only: true 
        - name: points | type: integer | description: Points earned and adjusted over the tier's current rolling window.  | read-only: true | validation: minimum 0
     - name: contact | type: Contact | description: Contact information.  | read-only: true 
        - name: _id | type: string | description: Contact GUID.  | read-only: true | validation: format GUID
        - name: name | type: string | description: Contact's first and last name.  | read-only: true 
        - name: picture | type: Image | description: Contact's profile picture.  | read-only: true 
           - name: _id | type: string | description: WixMedia image GUID.  
           - name: url | type: string | description: Image URL.  
           - name: height | type: integer | description: Original image height.  | read-only: true 
           - name: width | type: integer | description: Original image width.  | read-only: true 
        - name: email | type: string | description: Contact's email address.  | read-only: true | validation: format EMAIL
        - name: displayName | type: string | description: Contact's first and last name. If no name is provided, uses contact's email.  | read-only: true 
     - name: pointsExpiration | type: PointsExpiration | description: Points expiration information.  | read-only: true 
        - name: expirationDate | type: Date | description: Date and time at which points are expiring.  | read-only: true 
        - name: expiringPointsAmount | type: integer | description: Amount of points that are going to expire at that date.  | read-only: true 
  - name: pagingMetadata | type: CursorPagingMetadata | description: Paging metadata  
     - name: count | type: integer | description: Number of items returned in current page.  | validation: format int32
     - name: cursors | type: Cursors | description: Cursor strings that point to the next page, previous page, or both.  
        - name: next | type: string | description: Cursor string pointing to the next page in the list of results.  | validation: maxLength 16000
        - name: prev | type: string | description: Cursor pointing to the previous page in the list of results.  | validation: maxLength 16000
     - name: hasNext | type: boolean | description: Whether there are more pages to retrieve following the current page.  + `true`: Another page of results can be retrieved. + `false`: This is the last page.  


```

### Examples

### queryLoyaltyAccounts
```javascript
import { accounts } from '@wix/loyalty';

async function queryLoyaltyAccounts(query) {
  const response = await accounts.queryLoyaltyAccounts(query);
};
```

### queryLoyaltyAccounts (with elevated permissions)
```javascript
import { accounts } from '@wix/loyalty';
import { auth } from '@wix/essentials';

async function myQueryLoyaltyAccountsMethod(query) {
  const elevatedQueryLoyaltyAccounts = auth.elevate(accounts.queryLoyaltyAccounts);
  const response = await elevatedQueryLoyaltyAccounts(query);
}
```

### queryLoyaltyAccounts (self-managed)
Self-managed SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md).

```javascript
import { createClient } from '@wix/sdk';
import { accounts } from '@wix/loyalty';
// Import the auth strategy for the relevant access type
// Import the relevant host module if needed

const myWixClient = createClient ({
  modules: { accounts },
  // Include the auth strategy and host as relevant
});


async function queryLoyaltyAccounts(query) {
  const response = await myWixClient.accounts.queryLoyaltyAccounts(query);
};
```

---