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

# Marcar mensagem como lida

> Marque como lida uma mensagem recebida do contato

## Conceituação

Método para marcar como lida uma mensagem que o canal recebeu do contato. Funciona em canal **WhatsApp Oficial** (API oficial da Meta) e em canal **WhatsApp Web**, com o WhatsApp Web habilitado no workspace.

## Atributos

| Atributo | Uso |
| - | - |
| `messageId` | Obrigatório. O `messageId` que chegou no webhook da mensagem recebida. |
| `phone` | Obrigatório, como na Z-API, mas não é usado: a mensagem é encontrada pelo `messageId`. |

O corpo vai em JSON ou como formulário (`application/x-www-form-urlencoded` ou `multipart/form-data`).

A resposta de sucesso é `200`:

```json theme={null}
{ "value": true }
```

## Diferenças em relação à Z-API

* O `messageId` é o id da mensagem no Omni Z-API, o mesmo que chega no webhook. No formato padrão de webhook, é o `message._id`. Não é o id da mensagem no WhatsApp.
* No WhatsApp Oficial, a API da Meta (Cloud API) marca como lidas também as mensagens anteriores da conversa.
* Uma mensagem enviada pelo próprio canal responde `200`, sem efeito.

> [!NOTE]
>
> No WhatsApp Oficial, o [`send-text`](https://developer.omni.z-api.io/z-api/messages/send-text) com `delayTyping` também marca como lida a última mensagem recebida do contato, porque a Meta só mostra o "digitando" junto com a leitura. Quem usa essa opção vê a mensagem lida sem ter chamado esta rota.

## Erros

| Status | `error` | Quando |
| - | - | - |
| `400` | `phone is required` / `messageId is required` | `phone` ou `messageId` ausente ou vazio |
| `400` | `messageId is invalid` | `messageId` é `.` ou `..` |
| `400` | Varia, como `invalid character 'n' looking for beginning of object key string` | O corpo não pôde ser lido, como um JSON malformado |
| `404` | `message not found` | A mensagem não existe ou é de outro canal, com o canal conectado |
| `422` | `message cannot be marked as read: it has no id at the channel provider` | A mensagem não tem id no WhatsApp |
| `422` | `channel is disconnected` | O canal está desconectado. Vale para qualquer `messageId`, mesmo um que não existe: a conexão é conferida antes da mensagem |
| `422` | `the channel provider refused the request` | O provedor do canal recusou a leitura |
| `422` | `instance subscription is not active` | A assinatura do canal não está ativa |
| `422` | `Z-API (WhatsApp Web) instances are not enabled for this workspace` | Canal WhatsApp Web, com o WhatsApp Web não habilitado no workspace |
| `422` | `the Z-API instance of this channel is not provisioned` | Canal WhatsApp Web cuja instância ainda não foi provisionada. É conferido antes da mensagem |
| `422` | `message cannot be marked as read: its chat is not supported` | Canal WhatsApp Web, com uma mensagem de um chat que a rota não atende |
| `422` | `message action route is not available for <tipo> channels; ...` | O canal não é WhatsApp Oficial nem WhatsApp Web, como um canal Telegram |
| `502` | `failed to mark message as read` | Falha ao marcar como lida |

A recusa por tipo de canal termina com `available only on Z-API (WhatsApp Web) instances`. Esse final é o mesmo para toda rota recusada. Esta rota também funciona no WhatsApp Oficial.

A API não repete a chamada depois de um `502`. Você pode chamar de novo.


## OpenAPI

````yaml POST /read-message
openapi: 3.1.0
info:
  title: Omni Z-API - Z-API Compatibility
  description: Z-API compatible API to facilitate migration to Omni Z-API
  version: 1.0.0
servers:
  - url: https://zapi.omni.z-api.io/channels/{channel_id}/token/{channel_token}
    variables:
      channel_id:
        description: Channel ID (equivalent to Z-API instance_id)
        default: YOUR_CHANNEL
      channel_token:
        description: Channel token (equivalent to Z-API token)
        default: YOUR_TOKEN
security:
  - bearerAuth: []
paths:
  /read-message:
    post:
      tags:
        - Messages
      summary: Mark message as read
      description: >-
        Marks as read a message the channel received from the contact. It works
        on Official WhatsApp channels and on WhatsApp Web channels, with
        WhatsApp Web enabled in the workspace. The body goes as JSON or as a
        form (`application/x-www-form-urlencoded` or `multipart/form-data`). The
        `messageId` is the one that came in the received message webhook;
        `phone` is required, but not used.
      operationId: readMessage
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ReadMessageRequest'
            example:
              phone: '5511999999999'
              messageId: 019E6F1A93FE78DCB54332F9FF0CCAE7
      responses:
        '200':
          description: >-
            Message marked as read. A message sent by the channel itself also
            answers `200`, with no effect.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReadMessageResponse'
              example:
                value: true
        '400':
          description: >-
            `phone` or `messageId` missing or empty, `messageId` equal to `.` or
            `..`, or a body that could not be read, such as malformed JSON. For
            a body that could not be read, the text describes the reading error.
            Nothing is marked.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReadMessageError'
              examples:
                messageIdRequired:
                  summary: Missing messageId
                  value:
                    error: messageId is required
                messageIdInvalid:
                  summary: Invalid messageId
                  value:
                    error: messageId is invalid
                malformedBody:
                  summary: Malformed JSON
                  value:
                    error: >-
                      invalid character 'n' looking for beginning of object key
                      string
        '404':
          description: >-
            The message does not exist or belongs to another channel, with the
            channel connected. With the channel disconnected, the answer is
            `422` with `channel is disconnected`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReadMessageError'
              example:
                error: message not found
        '405':
          $ref: '#/components/responses/MethodNotAllowed'
        '422':
          description: >-
            The message cannot be marked as read: it has no WhatsApp id, the
            channel is disconnected, the channel provider refused, or the
            channel subscription is not active. The connection is checked before
            the message: with the channel disconnected, any `messageId` gets
            `channel is disconnected`, even one that does not exist. On a
            WhatsApp Web channel, `422` also comes for a workspace without
            WhatsApp Web enabled, an instance not provisioned yet (checked
            before the message) and a message from a chat the route does not
            serve. A channel that is neither Official WhatsApp nor WhatsApp Web,
            such as Telegram, gets `422` with the channel type in the text. That
            text ends with `available only on Z-API (WhatsApp Web) instances`,
            the same ending of every refused route; this route also works on
            Official WhatsApp.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReadMessageError'
              examples:
                channelDisconnected:
                  summary: Channel disconnected
                  value:
                    error: channel is disconnected
                channelType:
                  summary: Telegram channel
                  value:
                    error: >-
                      message action route is not available for BOT_TELEGRAM
                      channels; available only on Z-API (WhatsApp Web) instances
                zapiDisabled:
                  summary: WhatsApp Web not enabled in the workspace
                  value:
                    error: >-
                      Z-API (WhatsApp Web) instances are not enabled for this
                      workspace
                notProvisioned:
                  summary: WhatsApp Web instance not provisioned
                  value:
                    error: the Z-API instance of this channel is not provisioned
                chatNotSupported:
                  summary: Chat not served on WhatsApp Web
                  value:
                    error: >-
                      message cannot be marked as read: its chat is not
                      supported
        '502':
          description: >-
            Failed to mark as read. The API does not repeat the call: you can
            call again.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReadMessageError'
              example:
                error: failed to mark message as read
components:
  schemas:
    ReadMessageRequest:
      type: object
      required:
        - phone
        - messageId
      properties:
        phone:
          type: string
          description: >-
            Contact phone number (country code + area code + number). Required,
            as in Z-API, but not used
          example: '5511999999999'
        messageId:
          type: string
          description: >-
            The `messageId` of the received message, as it came in the webhook.
            It is the message id in Omni Z-API, not the WhatsApp id
          example: 019E6F1A93FE78DCB54332F9FF0CCAE7
    ReadMessageResponse:
      type: object
      properties:
        value:
          type: boolean
          description: '`true` when the read was accepted'
    ReadMessageError:
      type: object
      properties:
        error:
          type: string
          description: Error message
    Error:
      type: object
      properties:
        error:
          type: string
          description: Error message
  responses:
    MethodNotAllowed:
      description: >-
        HTTP method the route does not accept. The `error` and the `Allow`
        header list the methods the route accepts; on the send routes, only
        `POST`.
      headers:
        Allow:
          description: Methods the route accepts, separated by commas
          schema:
            type: string
          example: POST
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: 'method not allowed: use POST'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Secret Key generated in the Omni Z-API Security panel

````

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