# 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) · [Emails reference](/docs/tags/emails.md)

## List logs

`GET /v1/logs`

Sent and received mail in one list, newest first, with an opaque cursor bound to the filters. Sent mail is what listEmails returns (keys restricted to domains see their own domains); received mail is what listInboundMessages returns for the same credential: administrators see every received message, including unrouted mail, with delivery details; dashboard members see mail on receiving addresses; other credentials get sent mail only. kind, campaignId and a sent-mail status filter sent mail and leave received mail out; status=received or status=spam filter received mail and leave sent mail out. Each statement stops after 5 seconds: a request that needs longer is refused with 422 READ_TOO_LARGE. Narrow the dates or filters.

Operation ID: `listLogs`

Permission: Needs Sent mail: read for the sender domain.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `cursor` | query | string | no |  |
| `limit` | query | integer | no |  |
| `direction` | query | string | no |  |
| `search` | query | string | no | At least 3 characters: a shorter term is refused with 422 VALIDATION_FAILED. Sent mail: a literal, case-insensitive substring of the sender, recipients, subject or IDs. Received mail: a full-text match on sender, recipients, subject and body. |
| `status` | query | string | no | A sent-mail status lists sent mail only. received lists received mail that is not flagged as spam; spam lists received mail flagged as spam (spam is visible to administrators only, so dashboard members get none). Either leaves sent mail out, and is refused (403) to credentials that cannot read received mail, like direction=received. |
| `kind` | query | string | no | Sent mail only; received mail is left out when set. |
| `campaignId` | query | string | no | Sent mail only; received mail is left out when set. |
| `region` | query | string | no |  |
| `from` | query | string | no | Mail created (sent) or received at or after this instant. |
| `to` | query | string | no | Mail created (sent) or received before this instant. |
| `counts` | query | string | no | true adds counts: how many emails match each status and kind for these filters between from and to (all retained mail without them), whatever the cursor and limit. Counts that take longer than 2 seconds are refused with 422 READ_TOO_LARGE: narrow from and to. |


### TypeScript SDK

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

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

const result = await listLogs({
  client,
  throwOnError: true,
});

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

### cURL

```sh
curl --request GET \
  --url 'https://nightmail.dev/v1/logs' \
  --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 |
| --- | --- | --- | --- |
| `data` | object[] | yes |  |
| `data[].id` | string | yes | Email ID for sent mail (getEmail); message ID for received mail (getInboundMessage). |
| `data[].direction` | string | yes |  |
| `data[].untrustedContent` | boolean | yes | Received mail and sent mailbox replies can contain external sender content. |
| `data[].at` | string | yes | When the email was created (sent) or received. |
| `data[].status` | string | yes | Sent: the email status, or scheduled for a send waiting for its time (getEmail reads it as queued with scheduled true). Received: received, or spam when flagged (spam is shown to administrators only). |
| `data[].from` | object | yes |  |
| `data[].to` | string[] | yes | Sent: the To recipients (at most 20). Received: the addresses in the To header (at most 20). |
| `data[].toCount` | integer | yes | Total To recipients (may exceed to.length when shortened). |
| `data[].subject` | string | yes |  |
| `data[].stream` | string or null | yes | Sent mail only. |
| `data[].campaignId` | string or null | yes |  |
| `data[].scheduledAt` | string or null | yes | Sent mail that is scheduled: when it goes (UTC). Null for received mail. |
| `data[].simulated` | boolean | yes | Sent through the SES mailbox simulator. Always false for received mail. |
| `data[].attachmentCount` | integer or null | yes | Received mail only. |
| `data[].threadId` | string or null | yes | The conversation (getInboundThread): every received email's, and a sent email's when it is a reply from a receiving address or inbox, or its In-Reply-To named a stored message its sender could read. Null when the caller can read none of the conversation's received or stored messages, and for credentials that cannot read received mail. |
| `data[].threadCount` | integer or null | yes | Messages in that conversation the caller can read, this one included; null without threadId. |
| `data[].addresses` | array or null | yes | Received mail only: the receiving addresses it was delivered to that the caller can read. Empty for unrouted mail. |
| `data[].region` | string or null | yes | Null for received mail unless the caller is an administrator. |
| `data[].envelopeTo` | array or null | yes | Received mail, administrators only: the SMTP envelope recipients (at most 20). |
| `data[].envelopeToCount` | integer or null | yes | Received mail, administrators only: total SMTP envelope recipients. |
| `nextCursor` | string or null | yes |  |
| `received` | boolean | yes | Whether received mail is included: false for direction=sent, with a sent-only filter, or when the credential cannot read inbound mail. |
| `counts` | object | no | With counts=true only. |
| `counts.status` | object | yes | Emails per status (sent statuses, received and spam) between from and to, with every filter but status. A status with none is left out. |
| `counts.kind` | object | yes | Sent emails per kind between from and to, with every filter but kind. |
| `counts.capped` | object | yes | Always false: the counts are exact. Kept for compatibility from when each direction counted at most its 50,000 newest emails. |

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