> 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

# QueryTasks

# Package: crm

# Namespace: Tasks

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

## Permission Scopes:
Read Tasks: SCOPE.DC-CRM.READ-TASKS

## Introduction

Retrieves a list of tasks, given the specified paging, filtering, and sorting.

Query Tasks runs with the following defaults, which you can override:
- `createdDate` in `DESC` order

For field support for filters and sorting, see [Tasks: Supported Filters and Sorting](https://dev.wix.com/docs/rest/api-reference/crm/tasks/task-v2/filter-and-sort.md).

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

---

## REST API

### Schema

```
 Method: queryTasks
 Description: Retrieves a list of tasks, given the specified paging, filtering, and sorting.  Query Tasks runs with the following defaults, which you can override: - `createdDate` in `DESC` order  For field support for filters and sorting, see [Tasks: Supported Filters and Sorting](https://dev.wix.com/docs/rest/api-reference/crm/tasks/task-v2/filter-and-sort.md).  To learn about working with _Query_ methods, see [API Query Language](https://dev.wix.com/api/rest/getting-started/api-query-language), [Sorting and Paging](https://dev.wix.com/api/rest/getting-started/sorting-and-paging), and [Field Projection](https://dev.wix.com/api/rest/getting-started/field-projection).
 URL: https://www.wixapis.com/crm/tasks/v2/tasks/query
 Method: POST
 Method parameters:
   param name: query | type: CursorQuery    
     - name: cursorPaging | type: CursorPaging | description: Cursor token pointing to a page of results. Not used in the first request. Following requests use the cursor token and not `filter` or `sort`.  
        - name: limit | type: integer | description: Number of items to load.  | validation: minimum 0, maximum 1000, format int32
        - name: cursor | type: string | description: Pointer to the next or previous page in the list of results.  You can get the relevant cursor token from the `pagingMetadata` object in the previous call's response. Not relevant for the first request.  
        - name: filter | type: object | description: Filter object in the following format: `"filter" : { "fieldName1": "value1", "fieldName2":{"$operator":"value2"} }` Example of operators: `$eq`, `$ne`, `$lt`, `$lte`, `$gt`, `$gte`, `$in`, `$hasSome`, `$hasAll`, `$startsWith`, `$contains`  
        - name: sort | type: array<Sorting> | description: Sort object in the following format: `[{"fieldName":"sortField1","order":"ASC"},{"fieldName":"sortField2","order":"DESC"}]`  
           - name: fieldName | type: string | description: Name of the field to sort by.  
           - name: order | type: SortOrder | description: Sort order.  
                 - enum:
                 -     ASC: Sort by ascending order.
                 -     DESC: Sort by descending order.
 Query fields:
   - field: id | operators: $eq, $ne, $in | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: createdDate | operators: $eq, $ne, $gt, $lt, $gte, $lte | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: updatedDate | operators: $eq, $ne, $gt, $lt, $gte, $lte | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: dueDate | operators: $eq, $ne, $gt, $lt, $gte, $lte, $exists | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: status | operators: $eq, $ne, $in, $nin | sort: none | aggregatable: undefined | searchable: undefined
   - field: contact.id | operators: $eq, $ne, $in, $exists | sort: none | aggregatable: undefined | searchable: undefined
 Return type: QueryTasksResponse
  - name: tasks | type: array<Task> | description: The retrieved tasks.  
     - name: id | type: string | description: Task GUID.  | read-only: true | validation: format GUID
     - name: revision | type: string | description: Revision number, which increments by 1 each time the task is updated. To prevent conflicting changes, the existing `revision` must be used when updating a task.  | read-only: true | validation: format int64
     - name: title | type: string | description: Title of the task.  | validation: minLength 1, maxLength 250
     - name: description | type: string | description: Description of the task.  | validation: minLength 1, maxLength 500
     - name: createdDate | type: string | description: Date and time the task was created.  | read-only: true | validation: format date-time
     - name: updatedDate | type: string | description: Date and time the task was last updated.  | read-only: true | validation: format date-time
     - name: dueDate | type: string | description: Due date for the task.  | validation: format date-time
     - name: status | type: TaskStatus | description: Status of the task.  Default: `ACTION_NEEDED`  
         - enum:
         -     ACTION_NEEDED: Action needed.
         -     COMPLETED: Task completed.
     - name: source | type: TaskSource | description: Details about the task source.  
        - name: sourceType | type: SourceType | description: How the task was created.  | read-only: true 
             - enum:
             -     APP: Task was created by an app.
             -     USER: Task was created by a Wix user.
        - name: appId | type: string | description: App GUID, if the task was created by an app.  | read-only: true | validation: format GUID
        - name: userId | type: string | description: User GUID, if the task was created by a Wix user.  | read-only: true | validation: format GUID
     - name: contact | type: ContactInfo | description: Information about the contact associated with the task.  
        - name: id | type: string | description: GUID of the contact associated with the task.  | validation: format GUID
        - name: firstName | type: string | description: Contact's first name.  | read-only: true 
        - name: lastName | type: string | description: Contact's last name.  | read-only: true 
        - name: imageUrl | type: string | description: Contact's image URL.  | read-only: true 
        - name: email | type: string | description: Contact's primary email.  | read-only: true 
        - name: phone | type: string | description: Contact's primary phone.  | read-only: true 
        - name: imageUrlExpirationDate | type: string | description: Image URL expiration date.  | read-only: true | validation: format date-time
  - name: pagingMetadata | type: CursorPagingMetadata | description: Paging metadata.  
     - name: count | type: integer | description: Number of items returned in the response.  | validation: format int32
     - name: cursors | type: Cursors | description: Offset that was requested.  
        - name: next | type: string | description: Cursor pointing to next page in the list of results.  
        - name: prev | type: string | description: Cursor pointing to previous page in the list of results.  
     - name: hasNext | type: boolean | description: Indicates if there are more results after the current page. If `true`, another page of results can be retrieved. If `false`, this is the last page.  


```

### Examples

### Queries Tasks
Retrieves empty list when there is no tasks that match the filter

```curl
curl -X POST \
  'https://www.wixapis.com/crm/tasks/v2/tasks/query' \
  -H 'Authorization: <AUTH>' \
  -H 'Content-Type: application/json' \
  --data-raw '
  {
    "query": {
      "sort": [
        {
          "fieldName": "createdDate",
          "order": "ASC"
        }
      ],
      "filter": {
        "$and": [
          {
            "status": "COMPLETED"
          },
          {
            "updatedDate": {"lte": "2023-08-20T12:00:00.000Z"}
          }
        ]
      },
      "cursorPaging": {
        "limit": 5
      }
    }
  }'
```

### Queries second page Tasks
Retrieves tasks by a query with cursor

```curl
curl -X POST \
  'https://www.wixapis.com/crm/tasks/v2/tasks/query' \
  -H 'Authorization: <AUTH>' \
  -H 'Content-Type: application/json' \
  --data-raw '
  {
    "query": {
      "cursorPaging": {
        "limit": 50,
        "cursor": "f7ec4508392aacd205bf1d05054347c6d8f56a5b.Eh0qGwoZCgZzdGF0dXMSDxoNQUNUSU9OX05FRURFRBomCgdkdWVEYXRlGhsqGQoXCgokdGltZXN0YW1wEgkRAAAo9BmieEIiJDI5Mjk0ZDJmLTEyNWYtNGFhZC05OGUwLTE1NDcxZTZkZDhkZg"
      }
    }
  }'
```

### Queries first page Tasks
Retrieves tasks by a query with filter and sort

```curl
curl -X POST \
  'https://www.wixapis.com/crm/tasks/v2/tasks/query' \
  -H 'Authorization: <AUTH>' \
  -H 'Content-Type: application/json' \
  --data-raw '
  {
    "query": {
      "sort": [
        {
          "fieldName": "dueDate",
          "order": "DESC"
        }
      ],
      "filter": {
        "$and": [
          {
            "status": "ACTION_NEEDED"
          },
          {
            "dueDate": {"$gt": "2023-08-20T12:00:00.000Z"}
          },
          {
            "contact.id": "c3341c32-f40e-4de5-8e90-d181c9cddb04"
          }
        ]
      },
      "cursorPaging": {
        "limit": 1
      }
    }
  }'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.crm.tasks.queryTasks(query)
 Description: Retrieves a list of tasks, given the specified paging, filtering, and sorting.  Query Tasks runs with the following defaults, which you can override: - `createdDate` in `DESC` order  For field support for filters and sorting, see [Tasks: Supported Filters and Sorting](https://dev.wix.com/docs/rest/api-reference/crm/tasks/task-v2/filter-and-sort.md).  To learn about working with _Query_ methods, see [API Query Language](https://dev.wix.com/api/rest/getting-started/api-query-language), [Sorting and Paging](https://dev.wix.com/api/rest/getting-started/sorting-and-paging), and [Field Projection](https://dev.wix.com/api/rest/getting-started/field-projection).
 # 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: TaskQuery   | required: true 
     - name: cursorPaging | type: CursorPaging | description: Cursor token pointing to a page of results. Not used in the first request. Following requests use the cursor token and not `filter` or `sort`.  
        - name: limit | type: integer | description: Number of items to load.  | validation: minimum 0, maximum 1000, format int32
        - name: cursor | type: string | description: Pointer to the next or previous page in the list of results.  You can get the relevant cursor token from the `pagingMetadata` object in the previous call's response. Not relevant for the first request.  
        - name: filter | type: object | description: Filter object in the following format: `"filter" : { "fieldName1": "value1", "fieldName2":{"$operator":"value2"} }` Example of operators: `$eq`, `$ne`, `$lt`, `$lte`, `$gt`, `$gte`, `$in`, `$hasSome`, `$hasAll`, `$startsWith`, `$contains`  
        - name: sort | type: array<Sorting> | description: Sort object in the following format: `[{"fieldName":"sortField1","order":"ASC"},{"fieldName":"sortField2","order":"DESC"}]`  
           - name: fieldName | type: string | description: Name of the field to sort by.  
           - name: order | type: SortOrder | description: Sort order.  
                 - enum:
                 -     ASC: Sort by ascending order.
                 -     DESC: Sort by descending order.
 Query fields:
   - field: _id | operators: $eq, $ne, $in | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: _createdDate | operators: $eq, $ne, $gt, $lt, $gte, $lte | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: _updatedDate | operators: $eq, $ne, $gt, $lt, $gte, $lte | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: dueDate | operators: $eq, $ne, $gt, $lt, $gte, $lte, $exists | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: status | operators: $eq, $ne, $in, $nin | sort: none | aggregatable: undefined | searchable: undefined
   - field: contact._id | operators: $eq, $ne, $in, $exists | sort: none | aggregatable: undefined | searchable: undefined
 Return type: PROMISE<QueryTasksResponse>
  - name: tasks | type: array<Task> | description: The retrieved tasks.  
     - name: _id | type: string | description: Task GUID.  | read-only: true | validation: format GUID
     - name: revision | type: string | description: Revision number, which increments by 1 each time the task is updated. To prevent conflicting changes, the existing `revision` must be used when updating a task.  | read-only: true | validation: format int64
     - name: title | type: string | description: Title of the task.  | validation: minLength 1, maxLength 250
     - name: description | type: string | description: Description of the task.  | validation: minLength 1, maxLength 500
     - name: _createdDate | type: Date | description: Date and time the task was created.  | read-only: true 
     - name: _updatedDate | type: Date | description: Date and time the task was last updated.  | read-only: true 
     - name: dueDate | type: Date | description: Due date for the task.  
     - name: status | type: TaskStatus | description: Status of the task.  Default: `ACTION_NEEDED`  
         - enum:
         -     ACTION_NEEDED: Action needed.
         -     COMPLETED: Task completed.
     - name: source | type: TaskSource | description: Details about the task source.  
        - name: sourceType | type: SourceType | description: How the task was created.  | read-only: true 
             - enum:
             -     APP: Task was created by an app.
             -     USER: Task was created by a Wix user.
        - name: appId | type: string | description: App GUID, if the task was created by an app.  | read-only: true | validation: format GUID
        - name: userId | type: string | description: User GUID, if the task was created by a Wix user.  | read-only: true | validation: format GUID
     - name: contact | type: ContactInfo | description: Information about the contact associated with the task.  
        - name: _id | type: string | description: GUID of the contact associated with the task.  | validation: format GUID
        - name: firstName | type: string | description: Contact's first name.  | read-only: true 
        - name: lastName | type: string | description: Contact's last name.  | read-only: true 
        - name: imageUrl | type: string | description: Contact's image URL.  | read-only: true 
        - name: email | type: string | description: Contact's primary email.  | read-only: true 
        - name: phone | type: string | description: Contact's primary phone.  | read-only: true 
        - name: imageUrlExpirationDate | type: Date | description: Image URL expiration date.  | read-only: true 
  - name: pagingMetadata | type: CursorPagingMetadata | description: Paging metadata.  
     - name: count | type: integer | description: Number of items returned in the response.  | validation: format int32
     - name: cursors | type: Cursors | description: Offset that was requested.  
        - name: next | type: string | description: Cursor pointing to next page in the list of results.  
        - name: prev | type: string | description: Cursor pointing to previous page in the list of results.  
     - name: hasNext | type: boolean | description: Indicates if there are more results after the current page. If `true`, another page of results can be retrieved. If `false`, this is the last page.  


```

### Examples

### Retrieve all tasks
```javascript
import { tasks } from '@wix/crm';

export async function myQueryTasksFunction() {

  try {
    const queryResults = await tasks.queryTasks()
      .find();

    const items = queryResults.items;
    const firstItem = items[0];
    const pageSize = queryResults.pageSize;
    const hasNext = queryResults.hasNext();
    const hasPrev = queryResults.hasPrev();
    const length = queryResults.length;
    const query = queryResults.query;
    console.log('Retrieved items:', items);

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

/* Promise resolves to:
 * [
 *   {
 *     "revision": "1",
 *     "title": "Send email",
 *     "status": "ACTION_NEEDED",
 *     "source": {
 *       "sourceType": "APP",
 *       "appId": "151e476a-715e-ec33-db9a-a7ff4d51f70a"
 *     },
 *     "contact": {
 *       "firstName": "Julie",
 *       "lastName": "Jones",
 *       "email": "julie.jones@example.com",
 *       "phone": "+1 516-569-2772",
 *       "_id": "719784da-0361-4f86-b4a4-b38409d7bce1"
 *     },
 *     "_id": "37e5d602-adad-4ba3-ba3d-06384394fb9e",
 *     "_createdDate": "2024-01-18T13:47:38.292Z",
 *     "_updatedDate": "2024-01-18T13:47:38.292Z"
 *   },
 *   {
 *     "revision": "1",
 *     "title": "Update Contact",
 *     "description": "Add new label to sontact",
 *     "dueDate": "2024-03-15T00:00:00.000Z",
 *     "status": "ACTION_NEEDED",
 *     "source": {
 *       "sourceType": "APP",
 *       "appId": "151e476a-715e-ec33-db9a-a7ff4d51f70a"
 *     },
 *     "contact": {
 *       "firstName": "Julie",
 *       "lastName": "Jones",
 *       "email": "julie.jones@example.com",
 *       "phone": "+1 516-569-2772",
 *       "_id": "719784da-0361-4f86-b4a4-b38409d7bce1"
 *     },
 *     "_id": "cdc52d55-e3e8-4fb4-8413-f15838e352b1",
 *     "_createdDate": "2024-01-18T13:46:18.198Z",
 *     "_updatedDate": "2024-01-18T13:46:18.198Z"
 *   },
 *   {
 *     "revision": "1",
 *     "title": "Follow up",
 *     "dueDate": "2024-01-26T10:00:00.000Z",
 *     "status": "ACTION_NEEDED",
 *     "source": {
 *       "sourceType": "USER",
 *       "userId": "162e6672-d392-42f8-bf79-999ee633c92a"
 *     },
 *     "contact": {
 *       "firstName": "Jane",
 *       "lastName": "Doe",
 *       "email": "jane.doe1@example.com",
 *       "phone": "+1 214-533-2543",
 *       "_id": "dfcb4c01-7336-4b59-ae43-957cb89952ce"
 *     },
 *     "_id": "3a49f901-62d5-4ca2-a8e8-395c562a3f7b",
 *     "_createdDate": "2024-01-18T13:40:56.414Z",
 *     "_updatedDate": "2024-01-18T13:40:56.414Z"
 *   },
 *   {
 *     "revision": "1",
 *     "title": "Follow up",
 *     "description": "Send a follow up email",
 *     "status": "ACTION_NEEDED",
 *     "source": {
 *       "sourceType": "APP",
 *       "appId": "151e476a-715e-ec33-db9a-a7ff4d51f70a"
 *     },
 *     "contact": {
 *       "firstName": "Sally",
 *       "lastName": "Smith",
 *       "email": "sally.smith@example.com",
 *       "phone": "+1 524-624-2486",
 *       "_id": "5518ee7f-270e-40c4-b756-dad56e8f0ffc"
 *     },
 *     "_id": "3194f3f2-945f-4810-8905-d02b24f9e790",
 *     "_createdDate": "2024-01-18T11:35:29.092Z",
 *     "_updatedDate": "2024-01-18T11:35:29.092Z"
 *   }
 * ]
 */
```

### Retrieve all completed tasks (with elevated permissions)
```javascript
import { tasks } from '@wix/crm';
import { auth } from '@wix/essentials';

export async function queryCompletedTasksFunction() {
  try {
    const elevatedQueryTasks = auth.elevate(tasks.queryTasks);
    const queryResults = await elevatedQueryTasks()
      .eq("status", "COMPLETED")
      .ascending("_createdDate")
      .find();

    const items = queryResults.items;
    const firstItem = items[0];
    const pageSize = queryResults.pageSize;
    const hasNext = queryResults.hasNext();
    const hasPrev = queryResults.hasPrev();
    const length = queryResults.length;
    const query = queryResults.query;
    console.log('Retrieved items:', items);

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

/* Promise resolves to:
* [
 *   {
 *     "revision": "2",
 *     "title": "Follow up",
 *     "description": "Send a follow up email",
 *     "status": "COMPLETED",
 *     "source": {
 *       "sourceType": "APP",
 *       "appId": "151e476a-715e-ec33-db9a-a7ff4d51f70a"
 *     },
 *     "contact": {
 *       "firstName": "Sally",
 *       "lastName": "Smith",
 *       "email": "sally.smith@example.com",
 *       "phone": "+1 524-624-2486",
 *       "_id": "5518ee7f-270e-40c4-b756-dad56e8f0ffc"
 *     },
 *     "_id": "3194f3f2-945f-4810-8905-d02b24f9e790",
 *     "_createdDate": "2024-01-18T11:35:29.092Z",
 *     "_updatedDate": "2024-01-18T14:50:25.210Z"
 *   },
 *   {
 *     "revision": "2",
 *     "title": "Send email",
 *     "status": "COMPLETED",
 *     "source": {
 *       "sourceType": "APP",
 *       "appId": "151e476a-715e-ec33-db9a-a7ff4d51f70a"
 *     },
 *     "contact": {
 *       "firstName": "Julie",
 *       "lastName": "Jones",
 *       "email": "julie.jones@example.com",
 *       "phone": "+1 516-569-2772",
 *       "_id": "719784da-0361-4f86-b4a4-b38409d7bce1"
 *     },
 *     "_id": "37e5d602-adad-4ba3-ba3d-06384394fb9e",
 *     "_createdDate": "2024-01-18T13:47:38.292Z",
 *     "_updatedDate": "2024-01-18T14:50:29.878Z"
 *   }
 * ]
 */
```

### Retrieve all completed tasks
```javascript
import { tasks } from '@wix/crm';

export async function queryCompletedTasksFunction() {
  try {
    const queryResults = await tasks.queryTasks()
      .eq("status", "COMPLETED")
      .ascending("_createdDate")
      .find();

    const items = queryResults.items;
    const firstItem = items[0];
    const pageSize = queryResults.pageSize;
    const hasNext = queryResults.hasNext();
    const hasPrev = queryResults.hasPrev();
    const length = queryResults.length;
    const query = queryResults.query;
    console.log('Retrieved items:', items);

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

/* Promise resolves to:
* [
 *   {
 *     "revision": "2",
 *     "title": "Follow up",
 *     "description": "Send a follow up email",
 *     "status": "COMPLETED",
 *     "source": {
 *       "sourceType": "APP",
 *       "appId": "151e476a-715e-ec33-db9a-a7ff4d51f70a"
 *     },
 *     "contact": {
 *       "firstName": "Sally",
 *       "lastName": "Smith",
 *       "email": "sally.smith@example.com",
 *       "phone": "+1 524-624-2486",
 *       "_id": "5518ee7f-270e-40c4-b756-dad56e8f0ffc"
 *     },
 *     "_id": "3194f3f2-945f-4810-8905-d02b24f9e790",
 *     "_createdDate": "2024-01-18T11:35:29.092Z",
 *     "_updatedDate": "2024-01-18T14:50:25.210Z"
 *   },
 *   {
 *     "revision": "2",
 *     "title": "Send email",
 *     "status": "COMPLETED",
 *     "source": {
 *       "sourceType": "APP",
 *       "appId": "151e476a-715e-ec33-db9a-a7ff4d51f70a"
 *     },
 *     "contact": {
 *       "firstName": "Julie",
 *       "lastName": "Jones",
 *       "email": "julie.jones@example.com",
 *       "phone": "+1 516-569-2772",
 *       "_id": "719784da-0361-4f86-b4a4-b38409d7bce1"
 *     },
 *     "_id": "37e5d602-adad-4ba3-ba3d-06384394fb9e",
 *     "_createdDate": "2024-01-18T13:47:38.292Z",
 *     "_updatedDate": "2024-01-18T14:50:29.878Z"
 *   }
 * ]
 */
```

### Retrieve all tasks (with elevated permissions)
```javascript
import { tasks } from '@wix/crm';
import { auth } from '@wix/essentials';

const elevatedQueryTasks = auth.elevate(tasks.queryTasks);

export async function myQueryTasksFunction() {

  try {
    const queryResults = await elevatedQueryTasks()
      .find();

    const items = queryResults.items;
    const firstItem = items[0];
    const pageSize = queryResults.pageSize;
    const hasNext = queryResults.hasNext();
    const hasPrev = queryResults.hasPrev();
    const length = queryResults.length;
    const query = queryResults.query;
    console.log('Retrieved items:', items);

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

/* Promise resolves to:
 * [
 *   {
 *     "revision": "1",
 *     "title": "Send email",
 *     "status": "ACTION_NEEDED",
 *     "source": {
 *       "sourceType": "APP",
 *       "appId": "151e476a-715e-ec33-db9a-a7ff4d51f70a"
 *     },
 *     "contact": {
 *       "firstName": "Julie",
 *       "lastName": "Jones",
 *       "email": "julie.jones@example.com",
 *       "phone": "+1 516-569-2772",
 *       "_id": "719784da-0361-4f86-b4a4-b38409d7bce1"
 *     },
 *     "_id": "37e5d602-adad-4ba3-ba3d-06384394fb9e",
 *     "_createdDate": "2024-01-18T13:47:38.292Z",
 *     "_updatedDate": "2024-01-18T13:47:38.292Z"
 *   },
 *   {
 *     "revision": "1",
 *     "title": "Update Contact",
 *     "description": "Add new label to sontact",
 *     "dueDate": "2024-03-15T00:00:00.000Z",
 *     "status": "ACTION_NEEDED",
 *     "source": {
 *       "sourceType": "APP",
 *       "appId": "151e476a-715e-ec33-db9a-a7ff4d51f70a"
 *     },
 *     "contact": {
 *       "firstName": "Julie",
 *       "lastName": "Jones",
 *       "email": "julie.jones@example.com",
 *       "phone": "+1 516-569-2772",
 *       "_id": "719784da-0361-4f86-b4a4-b38409d7bce1"
 *     },
 *     "_id": "cdc52d55-e3e8-4fb4-8413-f15838e352b1",
 *     "_createdDate": "2024-01-18T13:46:18.198Z",
 *     "_updatedDate": "2024-01-18T13:46:18.198Z"
 *   },
 *   {
 *     "revision": "1",
 *     "title": "Follow up",
 *     "dueDate": "2024-01-26T10:00:00.000Z",
 *     "status": "ACTION_NEEDED",
 *     "source": {
 *       "sourceType": "USER",
 *       "userId": "162e6672-d392-42f8-bf79-999ee633c92a"
 *     },
 *     "contact": {
 *       "firstName": "Jane",
 *       "lastName": "Doe",
 *       "email": "jane.doe1@example.com",
 *       "phone": "+1 214-533-2543",
 *       "_id": "dfcb4c01-7336-4b59-ae43-957cb89952ce"
 *     },
 *     "_id": "3a49f901-62d5-4ca2-a8e8-395c562a3f7b",
 *     "_createdDate": "2024-01-18T13:40:56.414Z",
 *     "_updatedDate": "2024-01-18T13:40:56.414Z"
 *   },
 *   {
 *     "revision": "1",
 *     "title": "Follow up",
 *     "description": "Send a follow up email",
 *     "status": "ACTION_NEEDED",
 *     "source": {
 *       "sourceType": "APP",
 *       "appId": "151e476a-715e-ec33-db9a-a7ff4d51f70a"
 *     },
 *     "contact": {
 *       "firstName": "Sally",
 *       "lastName": "Smith",
 *       "email": "sally.smith@example.com",
 *       "phone": "+1 524-624-2486",
 *       "_id": "5518ee7f-270e-40c4-b756-dad56e8f0ffc"
 *     },
 *     "_id": "3194f3f2-945f-4810-8905-d02b24f9e790",
 *     "_createdDate": "2024-01-18T11:35:29.092Z",
 *     "_updatedDate": "2024-01-18T11:35:29.092Z"
 *   }
 * ]
 */
```

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

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


async function queryTasks(query) {
  const response = await myWixClient.tasks.queryTasks(query);
};
```

---