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

# Advanced message search

> Searches messages with advanced filters and multi-session support.

**Features:**
- If `sessionIds` is empty, searches all of the user's sessions
- Allows searching by `chatId` (database ID) OR by `phone` (contact number)
- Filters by message type, sender (fromMe), and date range
- Administrators can see messages from all users
- Regular users see only their own messages
- Polling support for real-time updates



## OpenAPI

````yaml /api-reference/openapi.en.json post /api/v1/chats/messages/search
openapi: 3.1.0
info:
  title: D-API - Complete WhatsApp Infrastructure
  description: >-
    A scalable, robust solution for automation managers, SaaS products and end
    users who need a reliable WhatsApp integration. It offers multiple
    simultaneous instances, real-time webhooks, an intuitive dashboard and a
    documented REST API with 99.9% uptime and latency under 30ms.
  version: 1.2.1
  contact:
    name: Suporte D-API
    email: suporte@d-api.cloud
    url: https://d-api.cloud
servers:
  - url: https://api.d-api.cloud
    description: Production
security:
  - ApiKeyAuth: []
tags:
  - name: Home
    description: Base endpoints
  - name: Sessions
    description: Endpoints for managing sessions
  - name: Messages
    description: Endpoints for sending messages
  - name: Cloud API
    description: >-
      WhatsApp Official API (Meta Cloud API): manual connection, template
      management (list/create/delete) and template sending.
  - name: IVR Calls
    description: 'Voice call dispatch (IVR): single or bulk, with audio or an IVR flow.'
  - name: SMS
    description: 'SMS sending: single or bulk.'
  - name: Commands
    description: >-
      Look up asynchronous commands (async: true) by the commandId returned when
      enqueued.
paths:
  /api/v1/chats/messages/search:
    post:
      tags:
        - Chat
      summary: Advanced message search
      description: >-
        Searches messages with advanced filters and multi-session support.


        **Features:**

        - If `sessionIds` is empty, searches all of the user's sessions

        - Allows searching by `chatId` (database ID) OR by `phone` (contact
        number)

        - Filters by message type, sender (fromMe), and date range

        - Administrators can see messages from all users

        - Regular users see only their own messages

        - Polling support for real-time updates
      operationId: postApiV1ChatsMessagesSearch
      parameters: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                sessionIds:
                  type: array
                  items:
                    type: string
                chatId:
                  type: string
                phone:
                  type: string
                search:
                  type: string
                sort_field:
                  anyOf:
                    - const: timestamp
                      type: string
                    - const: id
                      type: string
                sort_order:
                  anyOf:
                    - const: asc
                      type: string
                    - const: desc
                      type: string
                limit:
                  minimum: 1
                  maximum: 100
                  type: number
                page:
                  minimum: 1
                  type: number
                polling:
                  type: boolean
                pollingLastMessageId:
                  type: number
                pollingLastUpdate:
                  type: string
                type:
                  anyOf:
                    - const: text
                      type: string
                    - const: image
                      type: string
                    - const: video
                      type: string
                    - const: audio
                      type: string
                    - const: document
                      type: string
                    - const: sticker
                      type: string
                    - const: location
                      type: string
                    - const: contact
                      type: string
                    - const: reaction
                      type: string
                fromMe:
                  type: boolean
                dateFrom:
                  type: string
                dateTo:
                  type: string
              additionalProperties: false
          multipart/form-data:
            schema:
              type: object
              properties:
                sessionIds:
                  type: array
                  items:
                    type: string
                chatId:
                  type: string
                phone:
                  type: string
                search:
                  type: string
                sort_field:
                  anyOf:
                    - const: timestamp
                      type: string
                    - const: id
                      type: string
                sort_order:
                  anyOf:
                    - const: asc
                      type: string
                    - const: desc
                      type: string
                limit:
                  minimum: 1
                  maximum: 100
                  type: number
                page:
                  minimum: 1
                  type: number
                polling:
                  type: boolean
                pollingLastMessageId:
                  type: number
                pollingLastUpdate:
                  type: string
                type:
                  anyOf:
                    - const: text
                      type: string
                    - const: image
                      type: string
                    - const: video
                      type: string
                    - const: audio
                      type: string
                    - const: document
                      type: string
                    - const: sticker
                      type: string
                    - const: location
                      type: string
                    - const: contact
                      type: string
                    - const: reaction
                      type: string
                fromMe:
                  type: boolean
                dateFrom:
                  type: string
                dateTo:
                  type: string
              additionalProperties: false
          text/plain:
            schema:
              type: object
              properties:
                sessionIds:
                  type: array
                  items:
                    type: string
                chatId:
                  type: string
                phone:
                  type: string
                search:
                  type: string
                sort_field:
                  anyOf:
                    - const: timestamp
                      type: string
                    - const: id
                      type: string
                sort_order:
                  anyOf:
                    - const: asc
                      type: string
                    - const: desc
                      type: string
                limit:
                  minimum: 1
                  maximum: 100
                  type: number
                page:
                  minimum: 1
                  type: number
                polling:
                  type: boolean
                pollingLastMessageId:
                  type: number
                pollingLastUpdate:
                  type: string
                type:
                  anyOf:
                    - const: text
                      type: string
                    - const: image
                      type: string
                    - const: video
                      type: string
                    - const: audio
                      type: string
                    - const: document
                      type: string
                    - const: sticker
                      type: string
                    - const: location
                      type: string
                    - const: contact
                      type: string
                    - const: reaction
                      type: string
                fromMe:
                  type: boolean
                dateFrom:
                  type: string
                dateTo:
                  type: string
              additionalProperties: false
      responses:
        '200':
          description: Successful response
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: 'API Key for authentication. Format: <API_KEY>'

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.