# Nightmail API

Send, receive and reply to email on your own domains. 202 means queued, not delivered.

- [Interactive documentation](/docs)
- [OpenAPI 3.1 JSON](/openapi.json)
- [Agent index](/llms.txt)
- TypeScript package: `@nightmail/sdk`

[API index](/docs.md) · [Inbound threads reference](/docs/tags/inbound-threads.md)

## Get inbound thread

`GET /v1/inbound/threads/{threadId}`

Returns the most recent visible messages (default 25, maximum 100), oldest first within the page. Ties use message ID. Pages are also bounded by response size and may return fewer than limit messages; pass nextCursor as cursor for the older page. Body previews are capped at 8192 characters and address/reference lists at 20 items (with total counts in toCount, ccCount, replyToCount and referencesCount); getInboundMessage retrieves stored text, up to 100 addresses and attachment metadata. State and counts are scoped to visible addresses. Each statement stops after 3 seconds: a request that needs longer is refused with 422 READ_TOO_LARGE. Narrow the dates or filters.

Operation ID: `getInboundThread`

Permission: Needs Received mail: read for the address it reached, or a sender domain it was addressed to.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `threadId` | path | string | yes |  |
| `addressId` | query | string | no | Opaque inbound address ID (mbx_…). |
| `cursor` | query | string | no | Opaque cursor from the preceding page, with the same filters. |
| `limit` | query | integer | no |  |


### TypeScript SDK

```ts
import { createClient } from '@nightmail/sdk/client';
import { getInboundThread } from '@nightmail/sdk';

const client = createClient({
  baseUrl: 'https://nightmail.dev',
  auth: scheme => scheme.scheme === 'bearer'
    ? process.env.NIGHTMAIL_API_KEY
    : undefined,
});

const result = await getInboundThread({
  client,
  path: {
    "threadId": "thread_123"
  },
  throwOnError: true,
});

console.log(result.data);
```

### cURL

```sh
curl --request GET \
  --url 'https://nightmail.dev/v1/inbound/threads/thread_123' \
  --header "Authorization: Bearer $NIGHTMAIL_API_KEY"
```

### Responses

| Status | Description | Schema |
| --- | --- | --- |
| `200` | Success | object |
| `400`, `401`, `403`, `404`, `409`, `413`, `422`, `429`, `500`, `503` | Request failed; use error.code and requestId to diagnose. | object |

#### 200: Success

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | yes |  |
| `subject` | string | yes |  |
| `snippet` | string | yes |  |
| `lastMessageAt` | string | yes |  |
| `from` | object | yes | Sender of the newest visible message (the subject and snippet are from it). For a sent reply this is your own address. |
| `from.name` | string or null | yes |  |
| `from.address` | string | yes |  |
| `addressIds` | string[] | yes |  |
| `messageCount` | integer | yes | Distinct messages visible within the requested address scope. |
| `messages` | object[] | yes |  |
| `messages[].simulated` | boolean | no |  |
| `messages[].id` | string | yes |  |
| `messages[].threadId` | string | yes |  |
| `messages[].addressIds` | string[] | yes |  |
| `messages[].direction` | string | yes |  |
| `messages[].status` | string | yes |  |
| `messages[].from` | object | yes |  |
| `messages[].to` | object[] | yes | Addresses in the To header (at most 20 on conversation pages, up to 100 on getInboundMessage). |
| `messages[].toCount` | integer | yes | Total addresses in the To header (may exceed to.length when shortened). |
| `messages[].cc` | object[] | yes | Addresses in the Cc header (at most 20 on conversation pages, up to 100 on getInboundMessage). |
| `messages[].ccCount` | integer | yes | Total addresses in the Cc header (may exceed cc.length when shortened). |
| `messages[].replyTo` | object[] | yes | Addresses in the Reply-To header (at most 20 on conversation pages, up to 100 on getInboundMessage). |
| `messages[].replyToCount` | integer | yes | Total addresses in the Reply-To header (may exceed replyTo.length when shortened). |
| `messages[].subject` | string | yes |  |
| `messages[].snippet` | string | yes |  |
| `messages[].text` | string | yes |  |
| `messages[].replyText` | string | yes |  |
| `messages[].receivedAt` | string | yes |  |
| `messages[].bodyTruncated` | boolean | yes |  |
| `messages[].attachmentCount` | integer | yes |  |
| `messages[].read` | boolean | yes |  |
| `messages[].errorCode` | string or null | yes |  |
| `messages[].suppressionReason` | string or null | no | Reason recorded when this send was suppressed. For a multi-recipient send blocked locally, this is the first blocked recipient in To, Cc, Bcc order. |
| `messages[].emailId` | string or null | yes |  |
| `messages[].messageId` | string or null | yes | RFC Message-ID, not the Nightmail message ID (id). |
| `messages[].inReplyTo` | string or null | yes |  |
| `messages[].references` | string[] | yes | Message-IDs in the References header (at most 20 on conversation pages, up to 100 on getInboundMessage). |
| `messages[].referencesCount` | integer | yes | Total Message-IDs in the References header (may exceed references.length when shortened). |
| `addressStates` | object[] | yes |  |
| `addressStates[].addressId` | string | yes |  |
| `addressStates[].unreadCount` | integer | yes |  |
| `addressStates[].archived` | boolean | yes |  |
| `addressStates[].starred` | boolean | yes |  |
| `addressStates[].trashed` | boolean | yes |  |
| `addressStates[].spam` | boolean | yes |  |
| `addressStates[].labels` | string[] | yes |  |
| `nextCursor` | string or null | yes |  |

#### 400, 401, 403, 404, 409, 413, 422, 429, 500, 503: Request failed; use error.code and requestId to diagnose.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `error` | object | yes |  |
| `error.code` | string | yes |  |
| `error.message` | string | yes |  |
| `error.requestId` | string | yes |  |
| `error.field` | string | no |  |
| `error.retryable` | boolean | yes |  |
| `error.resetAt` | string | no | Next capacity change for a Hosted rolling send limit. |
| `error.details` | object[] | no | Every problem found, when there is more than one part, such as rule diagnostics with rule, line, column, message and hint, or a measurement, such as CONTENT_TOO_LARGE_TO_SCREEN with screenedBytes and limitBytes (and index in a batch). |
| `error.required` | object | no | On a 403 permission refusal: what the request needs that this credential lacks. The Nightmail-Required-Permission header says the same. |
