> 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

# QueryPolicies

# Package: eventManagement

# Namespace: PolicyManagement

# Method link: https://dev.wix.com/docs/api-reference/business-solutions/events/event-management/policies-v2/query-policies?apiView=SDK.md

## Permission Scopes:
Read Policies: SCOPE.DC-EVENTS.READ-POLICIES

## Introduction

Retrieves a list of policies according to the provided filters and paging.

---

## REST API

### Schema

```
 Method: queryPolicies
 Description: Retrieves a list of policies according to the provided filters and paging.
 URL: https://www.wixapis.com/events-policies/v2/policies/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: QueryV2   | 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 per page.  | validation: minimum 0, maximum 100, 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: <br/> `"filter" : { "fieldName1": "value1", "fieldName2":{"$operator":"value2"} }`. <br/> <br/> **Example:** <br/> `"filter" : { "id": "2224a9d1-79e6-4549-a5c5-bf7ce5aac1a5", "revision": {"$ne":"1"} }` <br/> <br/> See [supported fields and operators](https://dev.wix.com/api/rest/wix-events/policy-v2/filter-and-sort) for more information.  
        - name: sort | type: array<Sorting> | description: Sort object in the following format: <br/> `[{"fieldName":"sortField1"},{"fieldName":"sortField2","direction":"DESC"}]` <br/> <br/> **Example:** <br/> `[{"fieldName":"createdDate","direction":"DESC"}]` <br/> <br/> See [supported fields](https://dev.wix.com/api/rest/wix-events/policy-v2/filter-and-sort) for more information.  
           - name: fieldName | type: string | description: Name of the field to sort by.  | validation: maxLength 100
           - name: order | type: SortOrder | description: Sort order (ASC/DESC). Defaults to ASC  
                 - enum: ASC, DESC
 Query fields:
   - field: id | operators: $eq, $ne, $in, $nin, $lt, $lte, $gt, $gte, $exists | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: eventId | operators: $eq, $ne, $in, $nin, $lt, $lte, $gt, $gte, $exists | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: revision | operators: $eq, $ne, $in, $nin, $lt, $lte, $gt, $gte, $exists | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: name | operators: $eq, $ne, $in, $nin, $lt, $lte, $gt, $gte, $exists | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: body | operators: $eq, $ne, $in, $nin, $lt, $lte, $gt, $gte, $exists | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: createdDate | operators: $eq, $ne, $in, $nin, $lt, $lte, $gt, $gte, $exists | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: updatedDate | operators: $eq, $ne, $in, $nin, $lt, $lte, $gt, $gte, $exists | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
 Return type: QueryPoliciesResponse
  - name: policies | type: array<Policy> | description: List of policies.  
     - name: id | type: string | description: Policy GUID.  | read-only: true | validation: format GUID
     - name: revision | type: string | description: Revision number, which increments by 1 each time the policy is updated.  To prevent conflicting changes, the current revision must be used when updating a policy.  | read-only: true | validation: format int64
     - name: createdDate | type: string | description: Date and time the policy was created in `yyyy-mm-ddThh:mm:sssZ` format.  | read-only: true | validation: format date-time
     - name: updatedDate | type: string | description: Date and time the policy was updated in `yyyy-mm-ddThh:mm:sssZ` format.  | read-only: true | validation: format date-time
     - name: name | type: string | description: Policy name that is visible in the dashboard and checkout form.  Min: 1 character  <br/> Max: 40 characters  | validation: minLength 1, maxLength 40
     - name: body | type: string | description: Policy body. Usually contains various terms and conditions.  Min: 1 character Max: 50,000 characters  <b>Note:</b> You can format text using various HTML tags such as `<p>`, `<b>`, `<ul>`, etc.  | validation: minLength 1, maxLength 50000
     - name: eventId | type: string | description: GUID of the event to which the policy belongs.  | validation: format GUID, immutable
  - name: metadata | type: PagingMetadataV2 | description: Metadata for the paginated results.  
     - name: count | type: integer | description: Number of items returned in the response.  | validation: format int32
     - name: offset | type: integer | description: Offset that was requested.  | validation: format int32
     - name: total | type: integer | description: Total number of items that match the query. Returned if offset paging is used and the `tooManyToCount` flag is not set.  | validation: format int32
     - name: tooManyToCount | type: boolean | description: Flag that indicates the server failed to calculate the `total` field.  
     - name: cursors | type: Cursors | description: Cursors to navigate through the result pages using `next` and `prev`. Returned if cursor paging is used.  
        - 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.  


```

### Examples

### Query policies by event ID and sort by created date in descending order
```curl
curl -X POST 'https://www.wixapis.com/events/v2/policies/query' \
-H 'Content-Type: application/json' \
-H 'Authorization: <AUTH TOKEN>' \
--data-binary '{
  "query": {
    "filter": {
      "eventId": {
        "$eq": "9d720f99-1b5a-4141-9877-d32985391e18"
      }
    },
    "sort": [
      {
        "fieldName": "createdDate",
        "order": "DESC"
      }
    ]
  }
}'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.events.policies.queryPolicies(query)
 Description: Retrieves a list of policies according to the provided filters and paging.
 # 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: PolicyQuery   | 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 per page.  | validation: minimum 0, maximum 100, 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: <br/> `"filter" : { "fieldName1": "value1", "fieldName2":{"$operator":"value2"} }`. <br/> <br/> **Example:** <br/> `"filter" : { "id": "2224a9d1-79e6-4549-a5c5-bf7ce5aac1a5", "revision": {"$ne":"1"} }` <br/> <br/> See [supported fields and operators](https://dev.wix.com/api/rest/wix-events/policy-v2/filter-and-sort) for more information.  
        - name: sort | type: array<Sorting> | description: Sort object in the following format: <br/> `[{"fieldName":"sortField1"},{"fieldName":"sortField2","direction":"DESC"}]` <br/> <br/> **Example:** <br/> `[{"fieldName":"createdDate","direction":"DESC"}]` <br/> <br/> See [supported fields](https://dev.wix.com/api/rest/wix-events/policy-v2/filter-and-sort) for more information.  
           - name: fieldName | type: string | description: Name of the field to sort by.  | validation: maxLength 100
           - name: order | type: SortOrder | description: Sort order (ASC/DESC). Defaults to ASC  
                 - enum: ASC, DESC
 Query fields:
   - field: _id | operators: $eq, $ne, $in, $nin, $lt, $lte, $gt, $gte, $exists | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: eventId | operators: $eq, $ne, $in, $nin, $lt, $lte, $gt, $gte, $exists | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: revision | operators: $eq, $ne, $in, $nin, $lt, $lte, $gt, $gte, $exists | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: name | operators: $eq, $ne, $in, $nin, $lt, $lte, $gt, $gte, $exists | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: body | operators: $eq, $ne, $in, $nin, $lt, $lte, $gt, $gte, $exists | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: _createdDate | operators: $eq, $ne, $in, $nin, $lt, $lte, $gt, $gte, $exists | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: _updatedDate | operators: $eq, $ne, $in, $nin, $lt, $lte, $gt, $gte, $exists | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
 Return type: PROMISE<QueryPoliciesResponse>
  - name: policies | type: array<Policy> | description: List of policies.  
     - name: _id | type: string | description: Policy GUID.  | read-only: true | validation: format GUID
     - name: revision | type: string | description: Revision number, which increments by 1 each time the policy is updated.  To prevent conflicting changes, the current revision must be used when updating a policy.  | read-only: true | validation: format int64
     - name: _createdDate | type: Date | description: Date and time the policy was created in `yyyy-mm-ddThh:mm:sssZ` format.  | read-only: true 
     - name: _updatedDate | type: Date | description: Date and time the policy was updated in `yyyy-mm-ddThh:mm:sssZ` format.  | read-only: true 
     - name: name | type: string | description: Policy name that is visible in the dashboard and checkout form.  Min: 1 character  <br/> Max: 40 characters  | validation: minLength 1, maxLength 40
     - name: body | type: string | description: Policy body. Usually contains various terms and conditions.  Min: 1 character Max: 50,000 characters  <b>Note:</b> You can format text using various HTML tags such as `<p>`, `<b>`, `<ul>`, etc.  | validation: minLength 1, maxLength 50000
     - name: eventId | type: string | description: GUID of the event to which the policy belongs.  | validation: format GUID, immutable
  - name: metadata | type: PagingMetadataV2 | description: Metadata for the paginated results.  
     - name: count | type: integer | description: Number of items returned in the response.  | validation: format int32
     - name: offset | type: integer | description: Offset that was requested.  | validation: format int32
     - name: total | type: integer | description: Total number of items that match the query. Returned if offset paging is used and the `tooManyToCount` flag is not set.  | validation: format int32
     - name: tooManyToCount | type: boolean | description: Flag that indicates the server failed to calculate the `total` field.  
     - name: cursors | type: Cursors | description: Cursors to navigate through the result pages using `next` and `prev`. Returned if cursor paging is used.  
        - 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.  


```

### Examples

### Query Policies by name and sort by _createdDate in descending order
```javascript
import { policies } from '@wix/events';

//query policies
async function queryPolicies() {
   try {
    const items = await policies.queryPolicies()
      .eq('eventId', '3d3d5c04-ece0-45a8-85f0-11a58edaa192')
      .ascending('_createdDate')
      .find();
    return items;
  }
  catch (error) {
    console.error(error);
    // Handle the error
   } 
 };

/* Returns all found policies
{
  "_items": [
    {
      "_id": "96b39980-e4e1-44e3-9ef0-9bec41d1cc10",
      "revision": "6",
      "_createdDate": "2023-03-08T13:55:18.057Z",
      "_updatedDate": "2023-03-15T13:43:11.794Z",
      "name": "Terms and Conditions Event 2",
      "body": "<p>Nobody will be allowed admission to the Event without a valid ticket or pass.</p>",
      "eventId": "3d3d5c04-ece0-45a8-85f0-11a58edaa192"
    },
    {
      "_id": "850beadf-f367-4197-a0c8-6624cb3bcef9",
      "revision": "1",
      "_createdDate": "2023-03-15T13:49:27.023Z",
      "_updatedDate": "2023-03-15T13:49:27.023Z",
      "name": "Terms and Conditions Event 1",
      "body": "<p>Tickets to this Event are issued on behalf of the Organiser and are subject to the following terms and conditions.</p>",
      "eventId": "3d3d5c04-ece0-45a8-85f0-11a58edaa192"
    }
  ],
  "_originQuery": {
    "filterTree": {
      "$and": [
        {
          "eventId": "3d3d5c04-ece0-45a8-85f0-11a58edaa192"
        }
      ]
    },
    "invalidArguments": [],
    "encoder": {},
    "transformationPaths": {},
    "sort": [
      {
        "fieldName": "createdDate",
        "order": "ASC"
      }
    ],
    "paging": {},
    "pagingMethod": "CURSOR",
    "builderOptions": {
      "cursorWithEmptyFilterAndSort": true
    }
  },
  "_limit": 50,
  "_nextCursor": "",
  "_prevCursor": "",
  "cursors": {
    "next": "",
    "prev": ""
  }
}
*/
```

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

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


async function queryPolicies(query) {
  const response = await myWixClient.policies.queryPolicies(query);
};
```

---