> 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

# QueryContacts

# Package: contacts

# Namespace: ContactsServiceV4

# Method link: https://dev.wix.com/docs/api-reference/crm/members-contacts/contacts/contacts/contact-v4/query-contacts?apiView=SDK.md

## Permission Scopes:
Read Contacts: SCOPE.DC-CONTACTS.READ-CONTACTS

## Introduction

Retrieves a list of contacts, given the provided [paging](https://dev.wix.com/api/rest/getting-started/sorting-and-paging#getting-started_sorting-and-paging_paging), [filtering, and sorting](https://dev.wix.com/docs/rest/crm/members-contacts/contacts/contacts/contact-v4/sort-filter-and-search.md).

Up to 1,000 contacts can be returned per request.
Query Contacts runs with these defaults, which you can override:

- `createdDate` is sorted in `ASC` order
- `paging.limit` is `50`
- `paging.offset` is `0`


For field support for filters and sorting, see
[Contacts: Supported Filters and Sorting](https://dev.wix.com/docs/rest/crm/members-contacts/contacts/contacts/contact-v4/sort-filter-and-search.md).

>**Note:** This is the Contacts v4 method. [Contacts v5](https://dev.wix.com/docs/api-reference/crm/members-contacts/contacts/contacts-v5/query-contacts.md) has its own Query Contacts method.
>In the SDK, system field names start with an underscore, for example `_id` and `_createdDate`.

To learn about working with _Query_ methods, see
[API Query Language](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md),
[Sorting and Paging](https://dev.wix.com/docs/rest/articles/getting-started/sorting-and-paging.md),
and [Field Projection](https://dev.wix.com/docs/rest/articles/getting-started/field-projection.md).

---

## REST API

### Schema

```
 Method: queryContacts
 Description: Retrieves a list of contacts, given the provided [paging](https://dev.wix.com/api/rest/getting-started/sorting-and-paging#getting-started_sorting-and-paging_paging), [filtering, and sorting](https://dev.wix.com/docs/rest/crm/members-contacts/contacts/contacts/contact-v4/sort-filter-and-search.md).  Up to 1,000 contacts can be returned per request. Query Contacts runs with these defaults, which you can override:  - `createdDate` is sorted in `ASC` order - `paging.limit` is `50` - `paging.offset` is `0`   For field support for filters and sorting, see [Contacts: Supported Filters and Sorting](https://dev.wix.com/docs/rest/crm/members-contacts/contacts/contacts/contact-v4/sort-filter-and-search.md).  >**Note:** This is the Contacts v4 method. [Contacts v5](https://dev.wix.com/docs/api-reference/crm/members-contacts/contacts/contacts-v5/query-contacts.md) has its own Query Contacts method. >In the SDK, system field names start with an underscore, for example `_id` and `_createdDate`.  To learn about working with _Query_ methods, see [API Query Language](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md), [Sorting and Paging](https://dev.wix.com/docs/rest/articles/getting-started/sorting-and-paging.md), and [Field Projection](https://dev.wix.com/docs/rest/articles/getting-started/field-projection.md).
 URL: https://www.wixapis.com/contacts/v4/contacts/query
 Method: POST
 Method parameters:
   param name: query | type: Query    
        - name: filter | type: object | description: Filter object. See [API Query Language](https://dev.wix.com/api/rest/getting-started/api-query-language) for more information.  For a detailed list of supported filters, see [Supported Filters](https://dev.wix.com/api/rest/contacts/contacts/supported-filters).  
        - name: sort | type: array<Sorting> | description: Sorting options. See [Sorting and Paging](https://dev.wix.com/api/rest/getting-started/pagination) for more information.  Max: 1 sort object  | validation: maxItems 1
           - name: fieldName | type: string | description: Field to sort by.  Supported properties: `createdDate`, `lastActivity.activityDate`, `primaryInfo.email`, `info.name.first`, `info.name.last`, `info.company`, `info.jobTitle`, `info.birthdate`  | validation: maxLength 100
           - name: order | type: SortOrder | description: Sort order. Use `ASC` for ascending order or `DESC` for descending order.  Defaults to `ASC`.  
                 - enum: ASC, DESC
        - name: paging | type: Paging | description: Pagination options.  
           - name: limit | type: integer | description: Number of items to return. Learn more about pagination in [API Query Language](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md#paging).  Default: `50`. <br> Maximum: `1000`.  | validation: minimum 0, maximum 1000, format int32
           - name: offset | type: integer | description: Number of items to skip in the current sort order.  | validation: minimum 0, format int32
        - name: fields | type: array<string> | description: List of projected fields to return. If both `fields` and `fieldsets` are sent in the request, the union of both lists is returned. `id` and `revision` are always returned.  Supported properties: `source`, `createdDate`, `updatedDate`, `lastActivity`, `primaryInfo`, `info.name`, `info.emails`, `info.phones`, `info.addresses`, `info.company`, `info.jobTitle`, `info.picture`, `info.birthdate`, `info.locale`, `info.labelKeys`, `info.locations`, `info.extendedFields`  | validation: maxItems 100, maxLength 100
        - name: fieldsets | type: array<ContactFieldSet> | description: Predefined sets of fields to return. If both `fields` and `fieldsets` are sent in the request, the union of both lists is returned.  - `BASIC`: Returns `id`, `revision`, `primaryInfo`, `info.name`. - `COMMUNICATION_DETAILS`: Returns `id`, `revision`, `primaryInfo`, `info.name`, `info.emails`, `info.phones`, `info.addresses`. - `EXTENDED`: Returns `id`, `revision`, `primaryInfo`, `info.name`, `info.extendedFields`. - `FULL`: Returns all fields.  Default: If `fields` is omitted from the request, `FULL`.  | validation: maxItems 10
             - enum:
             -     BASIC: name, primaryEmail, primaryPhone
             -     COMMUNICATION_DETAILS: name, phones, emails, addresses
             -     EXTENDED: name, primaryInfo(email, phone), extendedFields
             -     FULL: Full contact object
   param name: search | type: search | description: Plain text search for an exact match.  Supported properties: `info.name.first`, `info.name.last`, `info.emails.email`, `info.phones.phone`  Max: 100 characters  | validation: maxLength 100
 Query fields:
   - field: id | operators: $eq, $ne, $in, $exists | sort: none | aggregatable: undefined | searchable: undefined
   - field: info.locale | operators: $eq, $ne, $in, $exists | sort: none | aggregatable: undefined | searchable: undefined
   - field: createdDate | operators: $eq, $ne, $gt, $lt, $gte, $lte | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: lastActivity.activityDate | operators: $eq, $ne, $gt, $lt, $gte, $lte | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: info.birthdate | operators: $eq, $ne, $gt, $lt, $gte, $lte | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: updatedDate | operators: $eq, $ne, $gt, $lt, $gte, $lte | sort: none | aggregatable: undefined | searchable: undefined
   - field: primaryInfo.email | operators: $eq, $ne, $in, $exists, $startsWith | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: info.name.first | operators: $eq, $ne, $in, $exists, $startsWith | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: info.name.last | operators: $eq, $ne, $in, $exists, $startsWith | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: info.company | operators: $eq, $ne, $in, $exists, $startsWith | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: info.jobTitle | operators: $eq, $ne, $in, $exists, $startsWith | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: primaryInfo.phone | operators: $eq, $ne, $in, $exists, $startsWith | sort: none | aggregatable: undefined | searchable: undefined
   - field: info.labelKeys | operators: $hasSome, $hasAll | sort: none | aggregatable: undefined | searchable: undefined
 Return type: QueryContactsResponse
  - name: contacts | type: array<Contact> | description: List of contacts.  
     - name: id | type: string | description: Contact GUID.  | read-only: true | validation: format GUID
     - name: revision | type: integer | description: Revision number, which increments by 1 each time the contact is updated. To prevent conflicting changes, the existing `revision` must be specified when updating a contact.  | read-only: true 
     - name: source | type: ContactSource | description: Details about the contact's source.  | read-only: true 
        - name: sourceType | type: ContactSourceType | description: Source type.  | read-only: true 
             - enum: OTHER, ADMIN, WIX_APP, IMPORT, THIRD_PARTY, WIX_BOOKINGS, WIX_CHAT, WIX_EMAIL_MARKETING, WIX_EVENTS, WIX_FORMS, WIX_GROUPS, WIX_HOTELS, WIX_MARKET_PLACE, WIX_MUSIC, WIX_RESTAURANTS, WIX_SITE_MEMBERS, WIX_STORES, WIX_CODE, HOPP
        - name: appId | type: string | description: App GUID, if the contact was created by an app.  | read-only: true | validation: format GUID
     - name: createdDate | type: string | description: Date and time the contact was created.  | read-only: true | validation: format date-time
     - name: updatedDate | type: string | description: Date and time the contact was last updated.  | read-only: true | validation: format date-time
     - name: lastActivity | type: ContactActivity | description: Details about the contact's last action in the site.  | read-only: true 
        - name: activityDate | type: string | description: Date and time of the last action.  | validation: format date-time
        - name: activityType | type: ContactActivityType | description: Contact's last action in the site.  
             - enum:
             -     GENERAL: Visited the site.
             -     CONTACT_CREATED: Became a new contact.
             -     MEMBER_LOGIN: Logged in.
             -     MEMBER_REGISTER: Requested a site membership.
             -     MEMBER_STATUS_CHANGED: Was approved, blocked, or unblocked.
             -     FORM_SUBMITTED: Submitted a form.
             -     INBOX_FORM_SUBMITTED: Started a chat.
             -     INBOX_PAYMENT_REQUEST_PAID: Paid a payment request.
             -     INBOX_MESSAGE_TO_CUSTOMER: Received a message from the site.
             -     INBOX_MESSAGE_FROM_CUSTOMER: Sent a new message to the site.
             -     NEWSLETTER_SUBSCRIPTION_FORM_SUBMITTED: Subscribed to a site newsletter through a form.
             -     NEWSLETTER_SUBSCRIPTION_UNSUBSCRIBE: Unsubscribed from a site newsletter.
             -     ECOM_PURCHASE: Made a purchase.
             -     ECOM_CART_ABANDON: Abandoned a shopping cart.
             -     ECOM_CHECKOUT_BUYER: Checked out shopping cart and submitted buyer info (but didn’t complete the purchase yet).
             -     BOOKINGS_APPOINTMENT: Booked an appointment.
             -     HOTELS_RESERVATION: Made a Wix Hotels reservation.
             -     HOTELS_PURCHASE: Paid for a Wix Hotels reservation.
             -     HOTELS_CONFIRMATION: Confirmed a Wix Hotels reservation.
             -     HOTELS_CANCEL: Canceled a Wix Hotels reservation.
             -     VIDEO_PURCHASE: Purchased a video.
             -     VIDEO_RENT: Rented a video.
             -     CASHIER_BUTTON_PURCHASE: Made a purchase with a pay button.
             -     ARENA_NEW_LEAD: Became a new Wix Marketplace lead.
             -     EVENTS_RSVP: RSVP'd to an event.
             -     INVOICE_PAY: Paid an invoice.
             -     INVOICE_OVERDUE: An invoice is now overdue.
             -     PRICE_QUOTE_ACCEPT: Accepted a price quote.
             -     PRICE_QUOTE_EXPIRE: A price quote has expired.
             -     RESTAURANTS_ORDER: Ordered food with Wix Restaurants.
             -     RESTAURANTS_RESERVATION: Made a Wix Restaurants reservation.
             -     SHOUTOUT_OPEN: Opened an email from the site.
             -     SHOUTOUT_CLICK: Clicked a link in an email from the site.
             -     CONTACT_MERGED: Merged with another contact.
             -     NEWSLETTER_SUBSCRIPTION_SUBSCRIBE: Subscribed to a site newsletter.
             -     NEWSLETTER_SUBSCRIPTION_PENDING: Subscription status to site newsletters is pending confirmation.
             -     NEWSLETTER_SUBSCRIPTION_NOT_SET: Subscription status to site newsletters is not set.
             -     PHONE_SUBSCRIPTION_SUBSCRIBE: Subscribed to phone notifications.
             -     PHONE_SUBSCRIPTION_PENDING: Subscription to phone notificatons is pending confirmation.
             -     PHONE_SUBSCRIPTION_NOT_SET: Subscription to phone notificatons is not set.
             -     PHONE_SUBSCRIPTION_UNSUBSCRIBE: Subscribed to phone notifications.
     - name: primaryInfo | type: PrimaryContactInfo | description: Contact's primary phone and email.  | read-only: true 
        - name: email | type: string | description: Primary email address.  This property reflects the email address in `info.emails` where `primary` is `true`.  | read-only: true | validation: format EMAIL
        - name: phone | type: string | description: Primary phone number.  This property reflects the phone number in `info.phones` where `primary` is `true`.  | read-only: true 
     - name: info | type: ContactInfo | description: Contact's details.  
        - name: name | type: ContactName | description: Contact's first and last name.  
           - name: first | type: string | description: Contact's first name.  | validation: maxLength 1000
           - name: last | type: string | description: Contact's last name.  | validation: maxLength 1000
        - name: emails | type: ContactEmailsWrapper | description: Contact's email addresses.  
           - name: items | type: array<ContactEmail> | description: List of up to 50 email addresses.  | validation: maxItems 50
              - name: id | type: string | description: Email GUID.  | read-only: true | validation: format GUID
              - name: tag | type: EmailTag | description: Email type.  `UNTAGGED` is shown as "Other" in the Contact List.  
                     - enum: UNTAGGED, MAIN, HOME, WORK
              - name: email | type: string | description: Email address.  | validation: minLength 1, maxLength 320
              - name: primary | type: boolean | description: Indicates whether this is the contact's primary email address. When changing `primary` to `true` for an email, the contact's other emails become `false`. Changing the primary email of a contact also affects the subscription status to marketing emails that are decided based on the primary email.  
        - name: phones | type: ContactPhonesWrapper | description: Contact's phone numbers.  
           - name: items | type: array<ContactPhone> | description: List of up to 50 phone numbers.  | validation: maxItems 50
              - name: id | type: string | description: Phone GUID.  | read-only: true | validation: format GUID
              - name: tag | type: PhoneTag | description: Phone type.  `UNTAGGED` is shown as "Other" in the Contact List.  
                     - enum: UNTAGGED, MAIN, HOME, MOBILE, WORK, FAX
              - name: countryCode | type: string | description: [ISO-3166 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) country code.  | validation: format COUNTRY
              - name: phone | type: string | description: Phone number.  | validation: minLength 1, maxLength 50
              - name: e164Phone | type: string | description: [ITU E.164-formatted](https://www.itu.int/rec/T-REC-E.164/) phone number. Automatically generated using `phone` and `countryCode`, pending both values are valid.  | read-only: true 
              - name: primary | type: boolean | description: Indicates whether this is the contact's primary phone number. When changing `primary` to `true` for a phone, the contact's `primary` field for other phones becomes `false`. Changing the primary phone number also affects the subscription status to SMS messages that are decided based on the primary phone.  
        - name: addresses | type: ContactAddressesWrapper | description: Contact's street addresses.  
           - name: items | type: array<ContactAddress> | description: List of up to 50 addresses.  | validation: maxItems 50
              - name: id | type: string | description: Street address GUID.  | read-only: true | validation: format GUID
              - name: tag | type: AddressTag | description: Address type. `UNTAGGED` is shown as "Other" in the Contact List.  
                     - enum: UNTAGGED, HOME, WORK, BILLING, SHIPPING
              - name: address | type: Address | description: Street address.  
                 - ONE-OF: 
                    - name: streetAddress | type: StreetAddress | description: Street address object, with number and name in separate fields.  
                       - name: number | type: string | description: Street number.  | validation: maxLength 100
                       - name: name | type: string | description: Street name.  | validation: maxLength 1000
                    - name: addressLine | type: string | description: Main address line, usually street and number, as free text.  | validation: maxLength 1000
                 - name: country | type: string | description: 2-letter country code in an [ISO-3166 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) format.  | validation: format COUNTRY
                 - name: subdivision | type: string | description: Code for a subdivision (such as state, prefecture, or province) in an [ISO 3166-2](https://en.wikipedia.org/wiki/ISO_3166-2) format.  | validation: maxLength 100
                 - name: city | type: string | description: City name.  | validation: maxLength 1000
                 - name: postalCode | type: string | description: Postal or zip code.  | validation: maxLength 100
                 - name: addressLine2 | type: string | description: Free text providing more detailed address information, such as apartment, suite, or floor.  | validation: maxLength 1000
        - name: company | type: string | description: Contact's company name.  | validation: maxLength 1000
        - name: jobTitle | type: string | description: Contact's job title.  | validation: maxLength 1000
        - name: birthdate | type: string | description: Birth date in `YYYY-MM-DD` format. For example, `2020-03-15`.  | validation: format LOCAL_DATE
        - name: locale | type: string | description: Locale in [IETF BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag) format. Typically, this is a lowercase 2-letter language code, followed by a hyphen, followed by an uppercase 2-letter country code. For example, `en-US` for U.S. English, and `de-DE` for Germany German.  | validation: format LANGUAGE_TAG
        - name: labelKeys | type: LabelsWrapper | description: List of contact's labels.  Labels are used to organize contacts. Labels can be added and removed using Label Contact and Unlabel Contact, respectively.  To view or manage contact labels, use the Labels API.  
           - name: items | type: array<string> | description: List of contact label keys.  Contact labels help categorize contacts. Label keys must exist to be added to the contact. Contact labels can be created or retrieved with Find or Create Label or List Labels.  | validation: maxItems 2000
        - name: extendedFields | type: ExtendedFieldsWrapper | description: Additional custom fields.  Empty fields are not returned.  
           - name: items | type: Map<string,Value> | description: Contact's extended fields, where each key is the field key, and each value is the field's value for the contact.  To view and manage extended fields, use the Extended Fields API.  | validation: format map
              - ONE-OF: 
                 - name: nullValue | type:  | description:   
                 - name: numberValue | type: number | description:   
                 - name: stringValue | type: string | description:   
                 - name: boolValue | type: boolean | description:   
                 - name: structValue | type: object | description:   
                 - name: listValue | type: ListValue | description:   
                    - name: values | type: array<Value> | description:   
        - name: picture | type: ContactPicture | description: Contact's profile picture.  
           - name: image | type: Image | description: Image. This can contain an image URL or a Wix Media image GUID.  
              - name: id | type: string | description: WixMedia image GUID. This property is written by Wix when an image is uploaded to the Wix Media Manager.  
              - name: url | type: string | description: Image source: Either a Media Manager URL or external URL.  
              - name: height | type: integer | description: Height of the original image.  
              - name: width | type: integer | description: Width of the original image.  
              - name: altText | type: string | description: Image alt text (optional).  
              - name: urlExpirationDate | type: string | description: Image URL expiration date (optional).  | read-only: true | validation: format date-time
     - name: primaryEmail | type: PrimaryEmail | description: Contact's primary email details.  | read-only: true 
        - name: email | type: string | description: Primary email address.  This field reflects the email address in `info.emails` where `primary` is `true`.  | read-only: true | validation: format EMAIL
        - name: subscriptionStatus | type: SubscriptionStatus | description: Indicates the recipient's opt-in or opt-out status for marketing emails.  Default: `NOT_SET`  | read-only: true 
             - enum:
             -     NO_SUBSCRIPTION_STATUS: No status exists.
             -     NOT_SET: No status specified.
             -     PENDING: Subscription confirmation was requested, but recipient hasn't confirmed yet.
             -     SUBSCRIBED: Recipient has opted in to marketing emails or SMS messages.
             -     UNSUBSCRIBED: Recipient has opted out of marketing emails or SMS messages.
        - name: deliverabilityStatus | type: EmailDeliverabilityStatus | description: Indicates last reported status of sent emails.  Default: `NOT_SET`  | read-only: true 
             - enum:
             -     NOT_SET: No status reported.
             -     VALID: Emails are being successfully delivered.
             -     BOUNCED: The last email to the recipient bounced or was rejected.
             -     SPAM_COMPLAINT: Recipient registered a spam complaint with their email provider.
             -     INACTIVE: Multiple emails have been delivered without any kind of engagement from the recipient.
     - name: primaryPhone | type: PrimaryPhone | description: Contact's primary phone details.  | read-only: true 
        - name: countryCode | type: string | description: Country code of the primary phone number in [ISO-3166 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) format.  | validation: format COUNTRY
        - name: e164Phone | type: string | description: Phone number in [ITU E.164](https://www.itu.int/rec/T-REC-E.164/) format. Automatically generated using `phone` and `countryCode` when both values are valid.  | read-only: true 
        - name: formattedPhone | type: string | description: Formatted phone. Automatically generated using `phone` and `countryCode`.  | read-only: true 
        - name: subscriptionStatus | type: SubscriptionStatus | description: Indicates the recipient's opt-in or opt-out status for SMS messages.  Default: - `NOT_SET` when the phone is a valid E164 phone. - `NO_SUBSCRIPTION_STATUS` when the phone is not a valid E164 phone.  | read-only: true 
        - name: phone | type: string | description: Primary phone number.  This field reflects the phone number in `info.phones` where `primary` is `true`.  | read-only: true 
  - name: pagingMetadata | type: PagingMetadata | description: Details on the paged set of results returned.  
     - name: count | type: integer | description: The number of items returned in this response.  | validation: format int32
     - name: offset | type: integer | description: The offset which was requested.  | validation: format int32
     - name: total | type: integer | description: The total number of items that match the query.  | validation: format int32
     - name: tooManyToCount | type: boolean | description: A flag that indicates the server failed to calculate 'total' field.  

 Possible Errors:
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: UNSUPPORTED_FILTER_VALUE_TYPE | Description: Unsupported filter value type.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: UNSUPPORTED_FILTER_VALUE | Description: Unsupported filter value.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: UNSUPPORTED_FILTER_OPERATOR | Description: Unsupported filter operator for the provided field.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: UNSUPPORTED_FILTER_FIELD_UNKNOWN | Description: Field doesn't exist and can't be filtered.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: UNSUPPORTED_FILTER | Description: At least 1 of the provided filters isn't supported.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: MALFORMED_FILTER | Description: Filter couldn't be parsed.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: ILLEGAL_LIMIT | Description: Illegal paging limit. The limit must be between 1 and 1,000.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: UNSUPPORTED_SORT_FIELD | Description: Unsupported sort field.


```

### Examples

### Query Contacts by Email
```curl
curl -X POST \
  'https://www.wixapis.com/contacts/v4/contacts/query' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: <AUTH>' \
  --data-binary '{
    "query": {
        "filter": {"info.emails.email": "email2@example.com"},
        "fieldsets": ["BASIC","COMMUNICATION_DETAILS"]
      }
    }'
```

### Query Contacts by Amount Spent, Sorted by First Name
```curl
curl -X POST \
  'https://www.wixapis.com/contacts/v4/contacts/query' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: <AUTH>' \
  --data-binary '{
    "query": {
        "filter":   {
            "info.extendedFields.ecom.totalSpentAmount": {"$lte": 50.0 }
        },
        "sort": [
            {
                "fieldName": "info.name.last",
                "order" : "ASC"
            }
        ],
        "fields": ["info.name", "info.extendedFields"],
        "paging": {
            "limit": 30,
            "offset": 30
          }
      }
  }'
```

### Query Contacts by Last Name
```curl
curl -X POST \
  'https://www.wixapis.com/contacts/v4/contacts/query' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: <AUTH>' \
  --data-binary '{
    "query": {
      "filter": {
        "info.name.last": "Smith"
      },
      "fieldsets": ["BASIC"]
    }
  }'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.crm.contacts.queryContacts(query, options)
 Description: Retrieves a list of contacts, given the provided [paging](https://dev.wix.com/api/rest/getting-started/sorting-and-paging#getting-started_sorting-and-paging_paging), [filtering, and sorting](https://dev.wix.com/docs/rest/crm/members-contacts/contacts/contacts/contact-v4/sort-filter-and-search.md).  Up to 1,000 contacts can be returned per request. Query Contacts runs with these defaults, which you can override:  - `createdDate` is sorted in `ASC` order - `paging.limit` is `50` - `paging.offset` is `0`   For field support for filters and sorting, see [Contacts: Supported Filters and Sorting](https://dev.wix.com/docs/rest/crm/members-contacts/contacts/contacts/contact-v4/sort-filter-and-search.md).  >**Note:** This is the Contacts v4 method. [Contacts v5](https://dev.wix.com/docs/api-reference/crm/members-contacts/contacts/contacts-v5/query-contacts.md) has its own Query Contacts method. >In the SDK, system field names start with an underscore, for example `_id` and `_createdDate`.  To learn about working with _Query_ methods, see [API Query Language](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md), [Sorting and Paging](https://dev.wix.com/docs/rest/articles/getting-started/sorting-and-paging.md), and [Field Projection](https://dev.wix.com/docs/rest/articles/getting-started/field-projection.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: ContactQuery   | required: true 
        - name: filter | type: object | description: Filter object. See [API Query Language](https://dev.wix.com/api/rest/getting-started/api-query-language) for more information.  For a detailed list of supported filters, see [Supported Filters](https://dev.wix.com/api/rest/contacts/contacts/supported-filters).  
        - name: sort | type: array<Sorting> | description: Sorting options. See [Sorting and Paging](https://dev.wix.com/api/rest/getting-started/pagination) for more information.  Max: 1 sort object  | validation: maxItems 1
           - name: fieldName | type: string | description: Field to sort by.  Supported properties: `createdDate`, `lastActivity.activityDate`, `primaryInfo.email`, `info.name.first`, `info.name.last`, `info.company`, `info.jobTitle`, `info.birthdate`  | validation: maxLength 100
           - name: order | type: SortOrder | description: Sort order. Use `ASC` for ascending order or `DESC` for descending order.  Defaults to `ASC`.  
                 - enum: ASC, DESC
        - name: paging | type: Paging | description: Pagination options.  
           - name: limit | type: integer | description: Number of items to return. Learn more about pagination in [API Query Language](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md#paging).  Default: `50`. <br> Maximum: `1000`.  | validation: minimum 0, maximum 1000, format int32
           - name: offset | type: integer | description: Number of items to skip in the current sort order.  | validation: minimum 0, format int32
   param name: options | type: QueryContactsOptions  none  
        - name: search | type: string | description: Plain text search for an exact match.  Supported properties: `info.name.first`, `info.name.last`, `info.emails.email`, `info.phones.phone`  Max: 100 characters  | validation: maxLength 100
 Query fields:
   - field: _id | operators: $eq, $ne, $in, $exists | sort: none | aggregatable: undefined | searchable: undefined
   - field: info.locale | operators: $eq, $ne, $in, $exists | sort: none | aggregatable: undefined | searchable: undefined
   - field: _createdDate | operators: $eq, $ne, $gt, $lt, $gte, $lte | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: lastActivity.activityDate | operators: $eq, $ne, $gt, $lt, $gte, $lte | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: info.birthdate | operators: $eq, $ne, $gt, $lt, $gte, $lte | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: _updatedDate | operators: $eq, $ne, $gt, $lt, $gte, $lte | sort: none | aggregatable: undefined | searchable: undefined
   - field: primaryInfo.email | operators: $eq, $ne, $in, $exists, $startsWith | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: info.name.first | operators: $eq, $ne, $in, $exists, $startsWith | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: info.name.last | operators: $eq, $ne, $in, $exists, $startsWith | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: info.company | operators: $eq, $ne, $in, $exists, $startsWith | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: info.jobTitle | operators: $eq, $ne, $in, $exists, $startsWith | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: primaryInfo.phone | operators: $eq, $ne, $in, $exists, $startsWith | sort: none | aggregatable: undefined | searchable: undefined
   - field: info.labelKeys | operators: $hasSome, $hasAll | sort: none | aggregatable: undefined | searchable: undefined
 Return type: PROMISE<QueryContactsResponse>
  - name: contacts | type: array<Contact> | description: List of contacts.  
     - name: _id | type: string | description: Contact GUID.  | read-only: true | validation: format GUID
     - name: revision | type: integer | description: Revision number, which increments by 1 each time the contact is updated. To prevent conflicting changes, the existing `revision` must be specified when updating a contact.  | read-only: true 
     - name: source | type: ContactSource | description: Details about the contact's source.  | read-only: true 
        - name: sourceType | type: ContactSourceType | description: Source type.  | read-only: true 
             - enum: OTHER, ADMIN, WIX_APP, IMPORT, THIRD_PARTY, WIX_BOOKINGS, WIX_CHAT, WIX_EMAIL_MARKETING, WIX_EVENTS, WIX_FORMS, WIX_GROUPS, WIX_HOTELS, WIX_MARKET_PLACE, WIX_MUSIC, WIX_RESTAURANTS, WIX_SITE_MEMBERS, WIX_STORES, WIX_CODE, HOPP
        - name: appId | type: string | description: App GUID, if the contact was created by an app.  | read-only: true | validation: format GUID
     - name: _createdDate | type: Date | description: Date and time the contact was created.  | read-only: true 
     - name: _updatedDate | type: Date | description: Date and time the contact was last updated.  | read-only: true 
     - name: lastActivity | type: ContactActivity | description: Details about the contact's last action in the site.  | read-only: true 
        - name: activityDate | type: Date | description: Date and time of the last action.  
        - name: activityType | type: ContactActivityType | description: Contact's last action in the site.  
             - enum:
             -     GENERAL: Visited the site.
             -     CONTACT_CREATED: Became a new contact.
             -     MEMBER_LOGIN: Logged in.
             -     MEMBER_REGISTER: Requested a site membership.
             -     MEMBER_STATUS_CHANGED: Was approved, blocked, or unblocked.
             -     FORM_SUBMITTED: Submitted a form.
             -     INBOX_FORM_SUBMITTED: Started a chat.
             -     INBOX_PAYMENT_REQUEST_PAID: Paid a payment request.
             -     INBOX_MESSAGE_TO_CUSTOMER: Received a message from the site.
             -     INBOX_MESSAGE_FROM_CUSTOMER: Sent a new message to the site.
             -     NEWSLETTER_SUBSCRIPTION_FORM_SUBMITTED: Subscribed to a site newsletter through a form.
             -     NEWSLETTER_SUBSCRIPTION_UNSUBSCRIBE: Unsubscribed from a site newsletter.
             -     ECOM_PURCHASE: Made a purchase.
             -     ECOM_CART_ABANDON: Abandoned a shopping cart.
             -     ECOM_CHECKOUT_BUYER: Checked out shopping cart and submitted buyer info (but didn’t complete the purchase yet).
             -     BOOKINGS_APPOINTMENT: Booked an appointment.
             -     HOTELS_RESERVATION: Made a Wix Hotels reservation.
             -     HOTELS_PURCHASE: Paid for a Wix Hotels reservation.
             -     HOTELS_CONFIRMATION: Confirmed a Wix Hotels reservation.
             -     HOTELS_CANCEL: Canceled a Wix Hotels reservation.
             -     VIDEO_PURCHASE: Purchased a video.
             -     VIDEO_RENT: Rented a video.
             -     CASHIER_BUTTON_PURCHASE: Made a purchase with a pay button.
             -     ARENA_NEW_LEAD: Became a new Wix Marketplace lead.
             -     EVENTS_RSVP: RSVP'd to an event.
             -     INVOICE_PAY: Paid an invoice.
             -     INVOICE_OVERDUE: An invoice is now overdue.
             -     PRICE_QUOTE_ACCEPT: Accepted a price quote.
             -     PRICE_QUOTE_EXPIRE: A price quote has expired.
             -     RESTAURANTS_ORDER: Ordered food with Wix Restaurants.
             -     RESTAURANTS_RESERVATION: Made a Wix Restaurants reservation.
             -     SHOUTOUT_OPEN: Opened an email from the site.
             -     SHOUTOUT_CLICK: Clicked a link in an email from the site.
             -     CONTACT_MERGED: Merged with another contact.
             -     NEWSLETTER_SUBSCRIPTION_SUBSCRIBE: Subscribed to a site newsletter.
             -     NEWSLETTER_SUBSCRIPTION_PENDING: Subscription status to site newsletters is pending confirmation.
             -     NEWSLETTER_SUBSCRIPTION_NOT_SET: Subscription status to site newsletters is not set.
             -     PHONE_SUBSCRIPTION_SUBSCRIBE: Subscribed to phone notifications.
             -     PHONE_SUBSCRIPTION_PENDING: Subscription to phone notificatons is pending confirmation.
             -     PHONE_SUBSCRIPTION_NOT_SET: Subscription to phone notificatons is not set.
             -     PHONE_SUBSCRIPTION_UNSUBSCRIBE: Subscribed to phone notifications.
     - name: primaryInfo | type: PrimaryContactInfo | description: Contact's primary phone and email.  | read-only: true 
        - name: email | type: string | description: Primary email address.  This property reflects the email address in `info.emails` where `primary` is `true`.  | read-only: true | validation: format EMAIL
        - name: phone | type: string | description: Primary phone number.  This property reflects the phone number in `info.phones` where `primary` is `true`.  | read-only: true 
     - name: info | type: ContactInfo | description: Contact's details.  
        - name: name | type: ContactName | description: Contact's first and last name.  
           - name: first | type: string | description: Contact's first name.  | validation: maxLength 1000
           - name: last | type: string | description: Contact's last name.  | validation: maxLength 1000
        - name: emails | type: ContactEmailsWrapper | description: Contact's email addresses.  
           - name: items | type: array<ContactEmail> | description: List of up to 50 email addresses.  | validation: maxItems 50
              - name: _id | type: string | description: Email GUID.  | read-only: true | validation: format GUID
              - name: tag | type: EmailTag | description: Email type.  `UNTAGGED` is shown as "Other" in the Contact List.  
                     - enum: UNTAGGED, MAIN, HOME, WORK
              - name: email | type: string | description: Email address.  | validation: minLength 1, maxLength 320
              - name: primary | type: boolean | description: Indicates whether this is the contact's primary email address. When changing `primary` to `true` for an email, the contact's other emails become `false`. Changing the primary email of a contact also affects the subscription status to marketing emails that are decided based on the primary email.  
        - name: phones | type: ContactPhonesWrapper | description: Contact's phone numbers.  
           - name: items | type: array<ContactPhone> | description: List of up to 50 phone numbers.  | validation: maxItems 50
              - name: _id | type: string | description: Phone GUID.  | read-only: true | validation: format GUID
              - name: tag | type: PhoneTag | description: Phone type.  `UNTAGGED` is shown as "Other" in the Contact List.  
                     - enum: UNTAGGED, MAIN, HOME, MOBILE, WORK, FAX
              - name: countryCode | type: string | description: [ISO-3166 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) country code.  | validation: format COUNTRY
              - name: phone | type: string | description: Phone number.  | validation: minLength 1, maxLength 50
              - name: e164Phone | type: string | description: [ITU E.164-formatted](https://www.itu.int/rec/T-REC-E.164/) phone number. Automatically generated using `phone` and `countryCode`, pending both values are valid.  | read-only: true 
              - name: primary | type: boolean | description: Indicates whether this is the contact's primary phone number. When changing `primary` to `true` for a phone, the contact's `primary` field for other phones becomes `false`. Changing the primary phone number also affects the subscription status to SMS messages that are decided based on the primary phone.  
        - name: addresses | type: ContactAddressesWrapper | description: Contact's street addresses.  
           - name: items | type: array<ContactAddress> | description: List of up to 50 addresses.  | validation: maxItems 50
              - name: _id | type: string | description: Street address GUID.  | read-only: true | validation: format GUID
              - name: tag | type: AddressTag | description: Address type. `UNTAGGED` is shown as "Other" in the Contact List.  
                     - enum: UNTAGGED, HOME, WORK, BILLING, SHIPPING
              - name: address | type: Address | description: Street address.  
                 - name: city | type: string | description: none  
                 - name: subdivision | type: string | description: none  
                 - name: country | type: string | description: none  
                 - name: postalCode | type: string | description: none  
                 - name: addressLine1 | type: string | description: none  
                 - name: addressLine2 | type: string | description: none  
        - name: company | type: string | description: Contact's company name.  | validation: maxLength 1000
        - name: jobTitle | type: string | description: Contact's job title.  | validation: maxLength 1000
        - name: birthdate | type: string | description: Birth date in `YYYY-MM-DD` format. For example, `2020-03-15`.  | validation: format LOCAL_DATE
        - name: locale | type: string | description: Locale in [IETF BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag) format. Typically, this is a lowercase 2-letter language code, followed by a hyphen, followed by an uppercase 2-letter country code. For example, `en-US` for U.S. English, and `de-DE` for Germany German.  | validation: format LANGUAGE_TAG
        - name: labelKeys | type: LabelsWrapper | description: List of contact's labels.  Labels are used to organize contacts. Labels can be added and removed using Label Contact and Unlabel Contact, respectively.  To view or manage contact labels, use the Labels API.  
           - name: items | type: array<string> | description: List of contact label keys.  Contact labels help categorize contacts. Label keys must exist to be added to the contact. Contact labels can be created or retrieved with Find or Create Label or List Labels.  | validation: maxItems 2000
        - name: extendedFields | type: ExtendedFieldsWrapper | description: Additional custom fields.  Empty fields are not returned.  
           - name: items | type: object | description: Contact's extended fields, where each key is the field key, and each value is the field's value for the contact.  To view and manage extended fields, use the Extended Fields API.  | validation: format map
        - name: picture | type: ContactPicture | description: Contact's profile picture.  
           - name: image | type: string | description: Image. This can contain an image URL or a Wix Media image GUID.  
     - name: primaryEmail | type: PrimaryEmail | description: Contact's primary email details.  | read-only: true 
        - name: email | type: string | description: Primary email address.  This field reflects the email address in `info.emails` where `primary` is `true`.  | read-only: true | validation: format EMAIL
        - name: subscriptionStatus | type: SubscriptionStatus | description: Indicates the recipient's opt-in or opt-out status for marketing emails.  Default: `NOT_SET`  | read-only: true 
             - enum:
             -     NO_SUBSCRIPTION_STATUS: No status exists.
             -     NOT_SET: No status specified.
             -     PENDING: Subscription confirmation was requested, but recipient hasn't confirmed yet.
             -     SUBSCRIBED: Recipient has opted in to marketing emails or SMS messages.
             -     UNSUBSCRIBED: Recipient has opted out of marketing emails or SMS messages.
        - name: deliverabilityStatus | type: EmailDeliverabilityStatus | description: Indicates last reported status of sent emails.  Default: `NOT_SET`  | read-only: true 
             - enum:
             -     NOT_SET: No status reported.
             -     VALID: Emails are being successfully delivered.
             -     BOUNCED: The last email to the recipient bounced or was rejected.
             -     SPAM_COMPLAINT: Recipient registered a spam complaint with their email provider.
             -     INACTIVE: Multiple emails have been delivered without any kind of engagement from the recipient.
     - name: primaryPhone | type: PrimaryPhone | description: Contact's primary phone details.  | read-only: true 
        - name: countryCode | type: string | description: Country code of the primary phone number in [ISO-3166 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) format.  | validation: format COUNTRY
        - name: e164Phone | type: string | description: Phone number in [ITU E.164](https://www.itu.int/rec/T-REC-E.164/) format. Automatically generated using `phone` and `countryCode` when both values are valid.  | read-only: true 
        - name: formattedPhone | type: string | description: Formatted phone. Automatically generated using `phone` and `countryCode`.  | read-only: true 
        - name: subscriptionStatus | type: SubscriptionStatus | description: Indicates the recipient's opt-in or opt-out status for SMS messages.  Default: - `NOT_SET` when the phone is a valid E164 phone. - `NO_SUBSCRIPTION_STATUS` when the phone is not a valid E164 phone.  | read-only: true 
        - name: phone | type: string | description: Primary phone number.  This field reflects the phone number in `info.phones` where `primary` is `true`.  | read-only: true 
  - name: pagingMetadata | type: PagingMetadata | description: Details on the paged set of results returned.  
     - name: count | type: integer | description: The number of items returned in this response.  | validation: format int32
     - name: offset | type: integer | description: The offset which was requested.  | validation: format int32
     - name: total | type: integer | description: The total number of items that match the query.  | validation: format int32
     - name: tooManyToCount | type: boolean | description: A flag that indicates the server failed to calculate 'total' field.  

 Possible Errors:
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: UNSUPPORTED_FILTER_VALUE_TYPE | Description: Unsupported filter value type.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: UNSUPPORTED_FILTER_VALUE | Description: Unsupported filter value.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: UNSUPPORTED_FILTER_OPERATOR | Description: Unsupported filter operator for the provided field.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: UNSUPPORTED_FILTER_FIELD_UNKNOWN | Description: Field doesn't exist and can't be filtered.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: UNSUPPORTED_FILTER | Description: At least 1 of the provided filters isn't supported.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: MALFORMED_FILTER | Description: Filter couldn't be parsed.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: ILLEGAL_LIMIT | Description: Illegal paging limit. The limit must be between 1 and 1,000.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: UNSUPPORTED_SORT_FIELD | Description: Unsupported sort field.


```

### Examples

### Query contacts by first name
Retrieve contacts whose first name starts with "J", newest first. Use `_createdDate`, not `createdDate`, as the sort field name.

```javascript
import { contacts } from '@wix/crm';

export async function myQueryContactsFunction() {
  try {
    const response = await contacts.queryContacts({
      filter: { 'info.name.first': { $startsWith: 'J' } },
      sort: [{ fieldName: '_createdDate', order: 'DESC' }],
      paging: { limit: 10, offset: 0 },
    });

    console.log('Contacts:', response.contacts);
    console.log('Total:', response.pagingMetadata?.total);

    return response;
  } catch (error) {
    console.log(error);
    // Handle the error
  }
}

/* Promise resolves to:
 * {
 *   "contacts": [
 *     {
 *       "_id": "2712ae1d-3f64-46c2-ac3a-94a6c2e29847",
 *       "revision": 17,
 *       "info": {
 *         "name": {
 *           "first": "John",
 *           "last": "Doe"
 *         }
 *       },
 *       "_createdDate": "2023-12-24T11:50:46.049Z",
 *       "_updatedDate": "2023-12-25T07:31:48.270Z"
 *     }
 *   ],
 *   "pagingMetadata": {
 *     "count": 1,
 *     "offset": 0,
 *     "total": 1
 *   }
 * }
 */

```

### queryContacts (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 { contacts } from '@wix/crm';
// Import the auth strategy for the relevant access type
// Import the relevant host module if needed

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


async function queryContacts(query,options) {
  const response = await myWixClient.contacts.queryContacts(query,options);
};
```

---