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

## List campaigns

`GET /v1/campaigns`

Returns bounded campaign metadata summaries. Fetch an individual campaign for its full editable draft; list drafts omit bodies, defaults, attachments and audience exclusions. Dashboard list counts may be cached for up to 60 seconds; API credentials get exact list counts. getCampaign may reuse counts for up to 20 seconds while a campaign of at least 10,000 recipients is preparing, scheduled, sending or paused. A newsletter's issues are the campaigns to its list: filter with listId.

Operation ID: `listCampaigns`

Permission: Needs Audience & content: read for the sender domain.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `cursor` | query | string | no |  |
| `limit` | query | integer | no |  |
| `region` | query | string | no |  |
| `state` | query | string | no | draft: editable. preparing: the audience is being frozen (for large lists) and every message is being validated in the background. scheduled: validated and waiting for scheduledAt. sending: recipients are being released into the dispatch queue. paused: releasing stopped by the user or the health check; queued mail still dispatches. done: every recipient was released and dispatched. failed: capture, preparation or releasing failed (delivery.error); edit or launch again. canceled: terminal. |
| `archived` | query | string | no | False lists active campaigns; true lists archived campaigns only. |
| `search` | query | string | no |  |
| `listId` | query | string | no | Only campaigns whose audience list is this one: a newsletter’s issues. |
| `newsletter` | query | string | no | true: only campaigns whose audience list is a newsletter. false: only the others, with no list or a list that is not a newsletter. |


### TypeScript SDK

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

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

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

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

### cURL

```sh
curl --request GET \
  --url 'https://nightmail.dev/v1/campaigns' \
  --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 |  |
| `data[].url` | string | yes | Dashboard URL for opening this campaign. Drafts open in the editor; launched campaigns open in review. |
| `data[].revision` | integer | yes |  |
| `data[].sourceTemplateId` | string or null | yes |  |
| `data[].sourceTemplateRevision` | integer or null | yes |  |
| `data[].state` | string | yes | draft: editable. preparing: the audience is being frozen (for large lists) and every message is being validated in the background. scheduled: validated and waiting for scheduledAt. sending: recipients are being released into the dispatch queue. paused: releasing stopped by the user or the health check; queued mail still dispatches. done: every recipient was released and dispatched. failed: capture, preparation or releasing failed (delivery.error); edit or launch again. canceled: terminal. |
| `data[].scheduledAt` | string or null | yes |  |
| `data[].archivedAt` | string or null | yes |  |
| `data[].createdAt` | string | yes |  |
| `data[].updatedAt` | string | yes |  |
| `data[].counts` | object | yes | Counts of immutable campaign email records grouped by their current status, not cumulative provider events or delivery rates. Drafts with no queued emails have zero counts. |
| `data[].delivery` | object or null | yes | The current launch: null until the campaign is sent or scheduled, and cleared by a new revision. |
| `data[].draft` | object | yes |  |
| `data[].stats` | object or null | yes | The campaign’s last stored count: the totals getCampaignStats reported when it was taken (computedAt). Null when it has none. Listing never counts emails or events; listing with listId starts a count for finished campaigns whose figures are missing or stale, so they appear on a later read. |
| `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. |
