> ## 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.

# Busca avançada de mensagens

> Busca mensagens com filtros avançados e suporte a múltiplas sessões.

**Funcionalidades:**
- Se `sessionIds` estiver vazio, busca em todas as sessões do usuário
- Permite buscar por `chatId` (ID do banco) OU por `phone` (número do contato)
- Filtros por tipo de mensagem, remetente (fromMe), e intervalo de datas
- Administradores podem ver mensagens de todos os usuários
- Usuários comuns veem apenas suas próprias mensagens
- Suporte a polling para atualizações em tempo real



## OpenAPI

````yaml /api-reference/openapi.json post /api/v1/chats/messages/search
openapi: 3.1.0
info:
  title: D-API - Infraestrutura WhatsApp Completa
  description: >-
    Solução escalável e robusta para gestores de automação, SaaS e usuários
    finais que precisam de uma integração WhatsApp confiável. Oferece múltiplas
    instâncias simultâneas, webhooks em tempo real, dashboard intuitivo e API
    REST documentada com 99.9% de uptime e latência inferior a 30ms.
  version: 1.2.0
  contact:
    name: Suporte D-API
    email: suporte@d-api.cloud
    url: https://d-api.cloud
servers:
  - url: https://api.d-api.cloud
    description: Produção
security:
  - ApiKeyAuth: []
tags:
  - name: Início
    description: Endpoints base
  - name: Sessões
    description: Endpoints para gerenciamento de sessões
  - name: Mensagens
    description: Endpoints para envio de mensagens
  - name: Ligações URA
    description: >-
      Disparo de ligações de voz (URA): individual ou em massa, com áudio ou
      fluxo IVR.
  - name: SMS
    description: 'Envio de SMS: individual ou em massa.'
paths:
  /api/v1/chats/messages/search:
    post:
      tags:
        - Chat
      summary: Busca avançada de mensagens
      description: >-
        Busca mensagens com filtros avançados e suporte a múltiplas sessões.


        **Funcionalidades:**

        - Se `sessionIds` estiver vazio, busca em todas as sessões do usuário

        - Permite buscar por `chatId` (ID do banco) OU por `phone` (número do
        contato)

        - Filtros por tipo de mensagem, remetente (fromMe), e intervalo de datas

        - Administradores podem ver mensagens de todos os usuários

        - Usuários comuns veem apenas suas próprias mensagens

        - Suporte a polling para atualizações em tempo real
      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
          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
          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
      responses:
        '200':
          description: Resposta bem-sucedida
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: 'API Key para autenticação. Formato: <API_KEY>'

````