# Mark a message as read

> Show a customer that you read their WhatsApp message, and optionally that you are typing a reply.

`POST https://api-connect.nxiom.com/api/v1/messaging/messages/{messageId}/read`

The customer sees blue ticks on their message. With `typing_indicator`, they also see that you are typing, until you send your next message or for up to 25 seconds.

## Authorization

Requires `whatsapp.send`. A key with `whatsapp.full_access` can also mark messages as read. WhatsApp must be turned on for your organization.

## Path parameters

| Field | Type | Description |
| --- | --- | --- |
| `messageId` | string · required | ID of a message a customer sent you, starting with `msg_`. |

## Body parameters

| Field | Type | Description |
| --- | --- | --- |
| `typing_indicator` | boolean · optional | Also show the customer that you are typing. Default `false`. |

The body can be left out.

## Request

### cURL

```shell
curl -X POST "https://api-connect.nxiom.com/api/v1/messaging/messages/msg_example/read" \
  -H "Authorization: Bearer $NEXIOM_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "typing_indicator": true
}'
```

### Node.js

```typescript
const apiKey = process.env.NEXIOM_API_KEY;
if (!apiKey) throw new Error('Set NEXIOM_API_KEY');

const response = await fetch(
  'https://api-connect.nxiom.com/api/v1/messaging/messages/msg_example/read',
  {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${apiKey}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      "typing_indicator": true
    }),
  },
);

const result = await response.json();
if (!response.ok) {
  throw new Error(result.message ?? `HTTP ${response.status}`);
}
console.log(result);
```

### PHP

```php
<?php

$apiKey = getenv('NEXIOM_API_KEY');
if (!$apiKey) {
    throw new RuntimeException('Set NEXIOM_API_KEY');
}

$request = curl_init("https://api-connect.nxiom.com/api/v1/messaging/messages/msg_example/read");
curl_setopt_array($request, [
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer $apiKey",
        "Content-Type: application/json",
    ],
    CURLOPT_POSTFIELDS => json_encode([
        "typing_indicator" => true,
    ], JSON_THROW_ON_ERROR),
]);

$raw = curl_exec($request);
$status = curl_getinfo($request, CURLINFO_HTTP_CODE);
$error = curl_error($request);
curl_close($request);

if ($raw === false) {
    throw new RuntimeException($error);
}
$result = json_decode($raw, true, 512, JSON_THROW_ON_ERROR);
if ($status >= 400) {
    throw new RuntimeException($result["message"] ?? "HTTP $status");
}
print_r($result);
```

## Response

HTTP `200`. Example identifiers below are illustrative.

### 200 OK

WhatsApp marked the message as read. The first time, the message's read_at is set to that time; marking it again keeps the first time.

```json
{
  "message": "Message marked as read",
  "data": {
    "id": "msg_example",
    "read": true
  }
}
```

### 400 Bad Request

The request is invalid. Correct it before retrying; `details` lists the failing fields.

```json
{
  "error": "invalid_argument",
  "message": "Request doesn't match the schema",
  "correlationId": "req_example",
  "details": {
    "context": "body",
    "issues": []
  }
}
```

### 401 Unauthorized

The API key is missing, malformed, revoked, or expired.

```json
{
  "error": "unauthorized",
  "message": "Invalid API key",
  "correlationId": "req_example"
}
```

### 403 Forbidden

The API key lacks whatsapp.send, or WhatsApp is not turned on for your organization (code: FEATURE_NOT_AVAILABLE).

```json
{
  "error": "not_allowed",
  "message": "Missing required API key permissions: whatsapp.send",
  "correlationId": "req_example"
}
```

### 404 Not Found

No message a customer sent has this ID in the key's project, or it was deleted after 30 days. Messages you sent can't be marked as read.

```json
{
  "error": "not_found",
  "code": "message_not_found",
  "message": "Message not found.",
  "correlationId": "req_example"
}
```

### 422 Unprocessable Entity

WhatsApp refused, or couldn't be reached. Nothing changed; you can try again.

```json
{
  "error": "unexpected_state",
  "code": "whatsapp_mark_read_failed",
  "message": "WhatsApp did not mark the message as read.",
  "correlationId": "req_example"
}
```

## Errors

| Status | `code` | Returned when |
| --- | --- | --- |
| `400` | none | The body has an unknown field, or `typing_indicator` isn't a boolean. |
| `401` | none | The API key is missing, malformed, revoked, or expired. |
| `403` | none | The key lacks the `whatsapp.send` permission. |
| `403` | `FEATURE_NOT_AVAILABLE` | WhatsApp is not turned on for your organization. |
| `404` | `message_not_found` | No received message with this ID exists in the key's project, or it was deleted after 30 days. |
| `422` | `whatsapp_mark_read_failed` | WhatsApp refused to mark the message as read; `message` includes WhatsApp's reason when it gave one. |
| `422` | `whatsapp_provider_unavailable` | WhatsApp couldn't be reached. Try again in a few minutes. |

---

Source: https://connect.nxiom.com/docs/api/messaging/read
