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

## Preview campaign audience

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

Counts the saved audience right now: matched contacts and how many are eligible, suppressed or unsubscribed. With readiness=true it also reviews the send (CampaignReadiness): whether it is ready to go out as it is, why, and the daily batches it recommends; send it with pacing.plan "recommended" to follow them. Read-only and never frozen; send or schedule takes its own snapshot and consent is rechecked at dispatch.

Operation ID: `previewCampaignAudience`

Permission: Needs Audience & content: read on the whole workspace.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes |  |
| `readiness` | query | string | no | Also review the send (readiness). |


### TypeScript SDK

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

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

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

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

### cURL

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

Live counts for the saved audience: matched contacts, those eligible for marketing, and the suppressed, unsubscribed or risky remainder. For a required notice everyone not suppressed or risky is eligible and unsubscribed is 0. Read-only; sending freezes its own snapshot and rechecks consent at dispatch.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `matched` | integer | yes |  |
| `eligible` | integer | yes |  |
| `suppressed` | integer | yes |  |
| `unsubscribed` | integer | yes |  |
| `risky` | integer | yes | Contacts who could receive it but are flagged as risky (a disposable inbox, a mistyped provider, a role address, an address known to be undeliverable): the send skips them. Not in eligible. |
| `riskyByReason` | object | yes |  |
| `riskyByReason.invalid` | integer | yes |  |
| `riskyByReason.disposable` | integer | yes |  |
| `riskyByReason.typo_domain` | integer | yes |  |
| `riskyByReason.role` | integer | yes |  |
| `riskyByReason.dead` | integer | yes |  |
| `riskyByReason.no_mail_domain` | integer | yes |  |
| `topicExcluded` | integer | no | With a topic: the subscribed contacts it leaves out (who opted out of it, or for a topic only people who opt in get, who didn’t). Counted in unsubscribed, not in eligible. |
| `approximate` | boolean | no | The topic’s effect on this list couldn’t be counted in time: eligible and topicExcluded are estimated from the workspace’s choices about the topic. Sending counts it exactly. |
| `readiness` | object or null | no | With readiness=true: the send review of a marketing campaign with a sender; null for a required notice or a draft without a sender. |
| `readiness.verdict` | string | yes | ready: send as you like. ramp_recommended: the plan is suggested. ramp_required: a Hosted send this large, from a new domain or far above anything its domain has sent, goes out with the plan (pacing.plan "recommended"), a daily limit no larger than its first day, or a confirmed consent source (consent); 422 RAMP_REQUIRED otherwise. |
| `readiness.summary` | string or null | yes | Why, in one or two plain sentences, when a ramp is recommended or required. |
| `readiness.reasons` | object[] | yes | The findings behind the verdict in the original codes, one per code: a newly registered domain, one new here and a new link domain read NEW_DOMAIN, a jump over the usual day SIZE_JUMP; blocklist findings appear only in findings. Prefer findings. |
| `readiness.findings` | object[] | no | Every finding behind the verdict, with its own code: NEW_REGISTRATION (registered recently, from public registry data), NEW_HERE (registered long ago, new to this workspace), NEW_DOMAIN (added recently, registration not known), USUAL_JUMP, NEW_LINK_DOMAIN, BLOCKLISTED_BEFORE (an earlier send drew replies naming a blocklist and none has finished without since), BLOCKLIST_UNCOUNTED (a recent send's blocklist replies aren't counted yet, so it isn't taken for clean), and the original codes. |
| `readiness.unavailable` | string | no | Present when part of the review couldn't be worked out just now (sizing the plan): what was left out, in a sentence. The review is then the one without that part, and its verdict is at least ramp_recommended. A launch that fails the same way is refused, 503 SEND_PLAN_UNAVAILABLE (retryable), with nothing sent. |
| `readiness.domain` | object | yes |  |
| `readiness.history` | object | yes |  |
| `readiness.list` | object | yes |  |
| `readiness.sizeJump` | number or null | yes | This send ÷ the largest campaign its domain sent in the last 90 days; null without one. |
| `readiness.usualJump` | number or null | no | This send ÷ the workspace's usual day (history.workspace.usualDay); null without one. |
| `readiness.plan` | object or null | yes | The recommended daily batches; null when one day covers everyone. |
| `readiness.required` | object 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. |
