> ## Documentation Index
> Fetch the complete documentation index at: https://docs.draftt.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Query policies with filtering, sorting and pagination

> Query policies with filtering, sorting and pagination



## OpenAPI

````yaml https://api.draftt.io/swagger post /policy/query
openapi: 3.1.0
info:
  title: Draftt API
  version: 0.2.1
servers:
  - url: https://api.draftt.io/v1
security:
  - BearerAuth: []
paths:
  /policy/query:
    post:
      tags:
        - Policy
      summary: Query policies with filtering, sorting and pagination
      description: Query policies with filtering, sorting and pagination
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PolicyQuery'
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PolicyResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '429':
          $ref: '#/components/responses/TooManyRequests'
        '500':
          $ref: '#/components/responses/InternalServerError'
components:
  schemas:
    PolicyQuery:
      type: object
      examples:
        - pageSize: 20
          filter:
            name:
              $like: End*
          sort:
            createdAt: desc
        - filter:
            name:
              $eq: End Of Life
          sort:
            name: asc
      properties:
        filter:
          $ref: '#/components/schemas/PolicyFilter'
        select:
          type: array
          description: >-
            If empty - will return all fields, if passed will only return
            selected fields
          items:
            type: string
            enum:
              - id
              - name
              - description
              - createdAt
              - updatedAt
        sort:
          type: object
          description: >-
            Optional sorting options, if not passed will sort by creation date
            in ascending order
          properties:
            id:
              type: string
              enum:
                - asc
                - desc
            name:
              type: string
              enum:
                - asc
                - desc
            description:
              type: string
              enum:
                - asc
                - desc
            createdAt:
              type: string
              enum:
                - asc
                - desc
            updatedAt:
              type: string
              enum:
                - asc
                - desc
          maxProperties: 2
        pageToken:
          type: string
          description: Base64 token for pagination
        pageSize:
          type: integer
          minimum: 1
          maximum: 1000
          default: 100
          description: Number of items to return per page
    PolicyResponse:
      type: object
      required:
        - items
      example:
        nextPageToken: >-
          eyJ1bmlxdWVGaWVsZE5hbWUiOiJpZCIsInNvcnQiOnsibmFtZSI6eyJkaXJlY3Rpb24iOiJhc2MifX19
        items:
          - id: '1'
            name: End Of Life
            description: All components should be in the supported version
            createdAt: '2024-05-06T11:25:51.513Z'
            updatedAt: '2024-09-09T19:35:31.898Z'
          - ...
      properties:
        items:
          type: array
          items:
            type: object
            properties:
              id:
                type: string
                format: int64
                description: Policy ID
              name:
                type: string
              description:
                oneOf:
                  - type: string
                  - type: 'null'
              createdAt:
                oneOf:
                  - type: string
                    format: date-time
                  - type: 'null'
              updatedAt:
                oneOf:
                  - type: string
                    format: date-time
                  - type: 'null'
        nextPageToken:
          oneOf:
            - type: string
              description: Token for fetching the next page of results
            - type: 'null'
    PolicyFilter:
      type: object
      properties:
        $and:
          type: array
          items:
            $ref: '#/components/schemas/PolicyFilter'
        $or:
          type: array
          items:
            $ref: '#/components/schemas/PolicyFilter'
        id:
          $ref: '#/components/schemas/NumberOperatorBlock'
        name:
          $ref: '#/components/schemas/StringOperatorBlock'
        description:
          $ref: '#/components/schemas/StringOperatorBlock'
        createdAt:
          $ref: '#/components/schemas/StringOperatorBlock'
        updatedAt:
          $ref: '#/components/schemas/StringOperatorBlock'
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
          required:
            - message
      required:
        - error
    NumberOperatorBlock:
      type: object
      properties:
        $eq:
          type: number
          description: Equals operator
        $ne:
          type: number
          description: Not equals operator
        $gt:
          type: number
          description: Greater than operator
        $gte:
          type: number
          description: Greater than or equal operator
        $lt:
          type: number
          description: Less than operator
        $lte:
          type: number
          description: Less than or equal operator
        $in:
          type: array
          items:
            type: number
          description: In operator
        $nin:
          type: array
          items:
            type: number
          description: Not in operator
        $exists:
          type: boolean
          description: Exists operator
      minProperties: 1
      maxProperties: 1
    StringOperatorBlock:
      type: object
      properties:
        $eq:
          type: string
          description: Equals operator
        $ne:
          type: string
          description: Not equals operator
        $gt:
          type: string
          description: Greater than operator
        $gte:
          type: string
          description: Greater than or equal operator
        $lt:
          type: string
          description: Less than operator
        $lte:
          type: string
          description: Less than or equal operator
        $like:
          type: string
          description: >-
            Like operator, wildrards are defind as `*`, for example - `{$like:
            'abc*'}` - starts with abc
        $in:
          type: array
          items:
            type: string
          description: In operator
        $nin:
          type: array
          items:
            type: string
          description: Not in operator
        $exists:
          type: boolean
          description: Exists operator
      minProperties: 1
      maxProperties: 1
  responses:
    BadRequest:
      description: Bad Request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Unauthorized:
      description: Unauthorized
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Forbidden:
      description: Forbidden
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    NotFound:
      description: Not Found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    TooManyRequests:
      description: Too Many Requests
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    InternalServerError:
      description: Internal Server Error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer

````