
## Conversation thread

`GET /v1/mail/messages/:id/thread`

Returns all messages of the conversation thread the specified message belongs to.

## Parameters

| Parameter | Type | Required | Description |
|----------|-----|:-----:|----------|
| `id` (path) | number | yes | Identifier of any message from the thread. List: `GET /v1/mail/messages` |

## Examples

### curl — personal key

```bash
curl "https://vibecode.bitrix24.com/v1/mail/messages/1763/thread" \
  -H "X-Api-Key: YOUR_API_KEY"
```

### curl — OAuth application

```bash
curl "https://vibecode.bitrix24.com/v1/mail/messages/1763/thread" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN"
```

### JavaScript — personal key

```javascript
const res = await fetch(
  'https://vibecode.bitrix24.com/v1/mail/messages/1763/thread',
  {
    headers: { 'X-Api-Key': 'YOUR_API_KEY' },
  }
)
const { success, data } = await res.json()
console.log(`Messages in thread: ${data.length}`)
```

### JavaScript — OAuth application

```javascript
const res = await fetch(
  'https://vibecode.bitrix24.com/v1/mail/messages/1763/thread',
  {
    headers: {
      'X-Api-Key': 'YOUR_APP_KEY',
      'Authorization': 'Bearer USER_SESSION_TOKEN',
    },
  }
)
const { success, data } = await res.json()
```

## Response fields

| Field | Type | Description |
|------|-----|----------|
| `success` | boolean | Always `true` on success |
| `data` | array | Array of thread messages, sorted by date |
| `data[].id` | number | Message identifier |
| `data[].subject` | string | Message subject |
| `data[].from` | string | Sender in the `Name <address>` format |
| `data[].to` | string | Recipient in the `Name <address>` format |
| `data[].cc` | string | Carbon copy of the message; an empty string `""` when there is no copy |
| `data[].date` | string | Sent date in the `YYYY-MM-DD HH:MM:SS` format (without timezone) |
| `data[].body` | string | Full message body with line breaks (`\r\n`) |

## Response example

```json
{
  "success": true,
  "data": [
    {
      "id": 1761,
      "subject": "Integration request",
      "from": "Support <support@example.com>",
      "to": "anna@example.com <anna@example.com>",
      "cc": "",
      "date": "2026-05-18 15:35:10",
      "body": "Hello! Please clarify the integration timeline.\r\n\r\n-- \r\nBest regards, support team"
    },
    {
      "id": 1763,
      "subject": "Re: Integration request",
      "from": "Anna Smith <anna@example.com>",
      "to": "Support <support@example.com>",
      "cc": "",
      "date": "2026-05-18 15:35:32",
      "body": "The timeline works. Thank you!"
    }
  ]
}
```

## Error response example

404 — message not found:

```json
{
  "success": false,
  "error": {
    "code": "ENTITY_NOT_FOUND",
    "message": "Record with ID = `999999999` not found"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|----------|
| 400 | `INVALID_PARAMS` | `id` is not a positive integer (message: `id must be a positive integer`) |
| 404 | `ENTITY_NOT_FOUND` | No message found with the given `id` |
| 403 | `SCOPE_DENIED` | The API key does not have the `mail` scope |
| 401 | `TOKEN_MISSING` | The API key has no configured Bitrix24 tokens |
| 429 | `RATE_LIMITED` | Request limit exceeded (header `Retry-After: 2`) |
| 502 | `BITRIX_UNAVAILABLE` | The Bitrix24 portal returned a 5xx error |
| 422 | `BITRIX_ERROR` | Other Bitrix24 errors |
| 401 | `MISSING_API_KEY` | The `X-Api-Key` header is missing |
| 401 | `INVALID_API_KEY` | Invalid API key |
| 401 | `KEY_INACTIVE` | The API key is deactivated |
| 401 | `KEY_EXPIRED` | The API key has expired |

Full list of common API errors — [Errors](/docs/errors).

## Known specifics

**The ID of any message in the thread returns the full thread.** A request with the `id` of any participant in the conversation returns the same complete set of messages.

## See also

- [List messages](./list.md)
- [Get message](./get.md)
- [Mail messages](/docs/mail/messages)
- [Mail](/docs/mail)
- [Authorization](/docs/keys-auth)
- [Errors](/docs/errors)
