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

## Get campaign stats

`GET /v1/campaigns/{id}/stats`

Lifetime campaign delivery and unique open/click statistics, progress, tracking setting and rates with numeric numerators/denominators. Counts distinct emails across all stored feedback, not event occurrences. Delivery/bounce/complaint rates use accepted emails; open/click rates use delivered emails. Both rate counts exclude simulated emails. Rates are fractions, null for zero denominators; engagement rates are also null with tracking disabled. Delivered means receiving-server acceptance, not inbox placement. Engagement includes bots/privacy proxies. Done means dispatch finished; asynchronous feedback can still change totals. A campaign of at least 20,000 recipients is counted in the background: about once a minute while it sends (every few minutes for the largest, so counting stays a small share of the database's time), once more when it finishes, and again when read more than 10 minutes later if anything changed. Its figures are the last count, so they can be minutes old; computedAt says when. A finished campaign keeps its figures after its emails leave the 30-day history. 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: `getCampaignStats`

Permission: Needs Sent mail: read on the whole workspace.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes |  |


### TypeScript SDK

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

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

const result = await getCampaignStats({
  client,
  path: {
    "id": "resource_123"
  },
  throwOnError: true,
});

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

### cURL

```sh
curl --request GET \
  --url 'https://nightmail.dev/v1/campaigns/resource_123/stats' \
  --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

Lifetime campaign statistics, with no date cutoff or pagination. Done means dispatch finished, not delivery finished. Feedback is asynchronous; missing engagement does not prove nobody read or clicked. Simulated outcomes are never evidence of real delivery.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | yes |  |
| `name` | string | yes |  |
| `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. |
| `tracking` | boolean | yes |  |
| `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. |
| `counts.total` | integer | yes |  |
| `counts.byStatus` | object | yes |  |
| `delivery` | object or null | yes | The current launch: null until the campaign is sent or scheduled, and cleared by a new revision. |
| `delivery.total` | integer | yes | Fixed recipient count once the audience is frozen (recipients expected while a large audience is being captured). |
| `delivery.prepared` | integer | yes | Recipients whose message was validated. |
| `delivery.expanded` | integer | yes | Recipients materialized as immutable email records. |
| `delivery.canceled` | integer | yes | Recipients canceled before materialization. Materialized cancellations remain in counts.byStatus.canceled. |
| `delivery.error` | object or null | yes | Why the campaign failed or was canceled by the system. |
| `delivery.pacing` | object | yes |  |
| `delivery.consent` | object or null | yes | The consent source confirmed at launch, if any. |
| `delivery.pausedAt` | string or null | yes |  |
| `delivery.pauseReason` | object or null | yes |  |
| `delivery.deliveredOnly` | boolean | yes | After a resumed list-probe quarantine: the rest goes only to contacts this workspace delivered to before; the others are counted in canceled. Never for a required notice. |
| `delivery.waiting` | object or null | yes | Why releasing recipients is currently held, and the best estimate of until when. list_probe: Hosted sent the first recipients (the list probe) and waits for their bounces and complaints before releasing the rest. feedback_lag: releasing is briefly held while priority safety feedback (bounces/complaints) catches up. ramp: a Hosted sender's first large campaigns release in growing hourly steps (sendEstimate.ramp); this hour's step is used up, or its delivery results are still coming in before the next step. link_record: the campaign has no host for its unsubscribe link right now (its workspace's sending is paused, or with own link hosts, its domain's isn't active yet); it continues by itself. |
| `delivery.stoppedDomains` | object[] | no | Recipient domains this campaign stopped sending to because its mail there kept bouncing for good (the rest of its recipients there are counted in canceled, are not charged and are not suppressed), oldest first, at most 50. Empty unless the guard is on. |
| `delivery.feedbackLag` | object or null | yes | Present while a campaign is preparing, sending, or paused when delivery feedback ingestion is at least 2 minutes behind. |
| `totals` | object | yes | Lifetime distinct email counts from current state and stored events; outcomes overlap. Accepted excludes simulated mail; other outcomes include simulated events for simulated mail. Opens and clicks include bots and privacy proxies. Failed means rejected or rendering failed; suppressed, canceled and uncertain mail remain in counts.byStatus. |
| `totals.accepted` | integer | yes |  |
| `totals.delivered` | integer | yes |  |
| `totals.bounced` | integer | yes |  |
| `totals.complained` | integer | yes |  |
| `totals.opened` | integer | yes |  |
| `totals.clicked` | integer | yes |  |
| `totals.failed` | integer | yes |  |
| `totals.deliveryDelayed` | integer | yes |  |
| `totals.simulated` | integer | yes |  |
| `rates` | object | yes |  |
| `rates.delivery` | object | yes | Delivered / accepted. Receiving-server acceptance, not inbox placement. |
| `rates.bounce` | object | yes | Bounced / accepted. |
| `rates.complaint` | object | yes | Complained / accepted. |
| `rates.open` | object | yes | Unique opened emails / delivered. |
| `rates.click` | object | yes | Unique clicked emails / delivered, not click-to-open rate. |
| `computedAt` | string | yes | When counts, totals and rates were counted: they include every change made before then. state and delivery are always current. |

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