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

## Schedule campaign

`POST /v1/campaigns/{id}/schedule`

Accept the current revision for durable scheduled delivery. Small audiences (<=5,000 list members) freeze immediately while larger audiences freeze and validate in the background during preparing; no recipient is materialized or sent before scheduledAt. The 202 queued count is recipients expected; delivery.total on GET /v1/campaigns/{id} is authoritative once the audience is frozen. Every email’s footer shows the workspace’s postal address under the Unsubscribe link, as US law (CAN-SPAM) requires, frozen as it is now: without one the request is refused with 422 POSTAL_ADDRESS_REQUIRED (set postalAddress with updateWorkspaceSettings). Hosted campaigns screen every distinct copy during launch and prepare before any row enters the sending queue, each distinct copy only once: recipients whose personalized copies read the same share one verdict. The campaign’s own copy, placeholders unresolved, is screened first and may hold 131,072 bytes of screened text (installation default; 422 CONTENT_TOO_LARGE_TO_SCREEN with error.details[0] { screenedBytes, limitBytes } otherwise); so may each copy. A failing copy never enters the sending queue (CONTENT_REJECTED_SPAM); when refused copies pass 5% and 10 recipients the campaign pauses once for review, and a positive verdict on the campaign’s own copy fails it before anyone is sent to. Audiences on lists up to 5,000 members freeze inside this request; larger audiences freeze in the background during preparing so this request returns immediately. CampaignQueued.queued is recipients expected; delivery.total on GET /v1/campaigns/{id} is authoritative once the audience is frozen. Late capture failures (such as EMPTY_AUDIENCE or AUDIENCE_LIMIT_EXCEEDED) move the campaign to failed with delivery.error and leave the draft editable.

Operation ID: `scheduleCampaign`

Permission: Needs Send email on the whole workspace. A person needs to be an owner or admin.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes |  |
| `Idempotency-Key` | header | string | no | Optional. Makes retries safe. Repeating a request with the same key and the same body returns the original result without performing the write again. While the first request with a key is still running, a duplicate returns 409 IDEMPOTENCY_IN_PROGRESS with Retry-After: retry with the same key, never a new one. Reusing a key with a different body returns 409 IDEMPOTENCY_CONFLICT. Keys are scoped to the API key and request path. This route's keys do not expire: a repeat with the same key replays the original result at any later time. Without a key, every request is processed, so a retried send can deliver twice. |

### Request body

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `revision` | integer | yes |  |
| `pacing` | object | no |  |
| `pacing.perDay` | integer or null | no | Release at most this many recipients per rolling 24-hour window. Omit or null for no daily cap. Delivery always also respects the SES 24-hour quota. |
| `pacing.autoPause` | boolean | no | Pause automatically if the bounce rate exceeds 2% (after 1,000 accepted) or the complaint rate exceeds 0.08% (after 5,000 accepted). Hosted shared sending requires true; false is rejected. |
| `pacing.rateShare` | number | no | Maximum fraction of the SES per-second send rate this campaign may use; the rest stays free for transactional mail and other campaigns. Defaults to 0.5 for paced campaigns; campaigns sent without pacing use the full rate. |
| `pacing.plan` | string | no | Send in the daily batches previewCampaignAudience recommends (readiness.plan), worked out again at launch: the most engaged contacts first, never-mailed last. Not with perDay. |
| `consent` | object | no | The sender confirms everyone on the list agreed to this mail, and where that consent comes from. Lets a send the review requires a ramp for (readiness.verdict ramp_required) go out without the plan. Stored with the campaign, with who and when, and in the workspace's Activity. An agent asks the person first. |
| `consent.confirmed` | boolean | yes |  |
| `consent.source` | string | yes | Where this list's consent comes from, for example "Signed up at checkout on our site since 2023". |
| `confirmRequiredNotice` | boolean | no | Required for a required notice (422 REQUIRED_NOTICE_UNCONFIRMED without it): the sender confirms it is a required notice with no promotion. Recorded with who and when. An agent asks the person first. |
| `scheduledAt` | string | yes |  |

### TypeScript SDK

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

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

const result = await scheduleCampaign({
  client,
  path: {
    "id": "resource_123"
  },
  body: {
    "revision": 1,
    "scheduledAt": "2026-09-18T19:00:00Z"
  },
  throwOnError: true,
});

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

### cURL

```sh
curl --request POST \
  --url 'https://nightmail.dev/v1/campaigns/resource_123/schedule' \
  --header "Authorization: Bearer $NIGHTMAIL_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
  "revision": 1,
  "scheduledAt": "2026-09-18T19:00:00Z"
}'
```

### Responses

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

#### 202: Success

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | yes |  |
| `state` | string | yes |  |
| `queued` | integer | yes | Recipients expected (exact for lists up to 5,000 members and unsegmented lists once list counts are enabled; may be 0 if an uncounted large list exceeds the 200 ms launch budget without a prior preview); delivery.total is authoritative once the audience is frozen. |
| `scheduledAt` | string or null | yes |  |
| `simulated` | boolean | yes |  |
| `risky` | object or null | no | Recipients the send skips as risky contacts, by reason: exact when queued is; null when a large audience could not be counted at launch. |
| `risky.total` | integer | yes |  |
| `risky.byReason` | object | yes |  |
| `readiness` | object or null | no | The send review as of the launch (list.neverMailed is not counted then); null for a required notice. |
| `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. |
