NightmailDocs
Docs

Update campaign

patch/v1/campaigns/{id}

Replace the whole draft at the current revision. Read the campaign first: html is block HTML that people may have edited in the dashboard composer, so send the complete updated html rather than a fragment. Rejected content names the unsupported tag or attribute. A failed campaign becomes a draft again.

Needs Send email for the sender domain.

Example

import { createClient } from '@nightmail/sdk/client';
import { updateCampaign } from '@nightmail/sdk';

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

const result = await updateCampaign({
  client,
  path: {
    "id": "resource_123"
  },
  body: {
    "revision": 1,
    "draft": {
      "name": "Example",
      "from": "sender@example.com",
      "replyTo": [],
      "subject": "Hello from Nightmail",
      "attachments": [],
      "tracking": true,
      "audience": {},
      "defaults": {}
    }
  },
  throwOnError: true,
});

console.log(result.data);
curl --request PATCH \
  --url 'https://nightmail.dev/v1/campaigns/resource_123' \
  --header "Authorization: Bearer $NIGHTMAIL_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
  "revision": 1,
  "draft": {
    "name": "Example",
    "from": "sender@example.com",
    "replyTo": [],
    "subject": "Hello from Nightmail",
    "attachments": [],
    "tracking": true,
    "audience": {},
    "defaults": {}
  }
}'

Parameters

idrequiredpath · string

Request body

CampaignUpdateInput
revisionrequiredinteger
draftrequiredobject
draft.namerequiredstring
draft.fromstring or string
draft.fromNamestring
draft.previewTextstring

Optional preheader text. Inserted as escaped hidden text into each outgoing HTML snapshot; draft HTML is unchanged. When set, supply HTML without its own duplicate preheader.

draft.replyTostring[]
draft.regionstring

Omit to keep the current region selection. An unpinned regional MX draft follows its From domain.

draft.regionPinnedboolean

Regional MX only. False follows the From domain; the displayed region is a hint. A supplied region on create or a changed region on edit pins it. To unpin, pass false and omit region.

draft.subjectstring or string
draft.attachmentsstring[]

IDs of files uploaded first (uploadAttachment). One file is at most 8 MiB decoded when sent as base64 in JSON (POST /v1/attachments), or 25 MiB as raw bytes (POST /v1/attachments/upload, with the name URI-encoded in X-Nightmail-Filename and the type in Content-Type). One email carries at most 100 files and 25 MiB of them together, decoded. A workspace keeps at most 100 GiB of uploaded files. For anything larger, link to the file from the email.

draft.trackingboolean
draft.audienceobject
draft.defaultsobject

Up to 100 key/value pairs, at most 64 KiB of JSON total.

draft.unsubscribePageUrlstring

Your own unsubscribe or preference page: HTTPS, no user name, password, whitespace or unsubscribe_token parameter, at most 1,000 characters. The footer's Unsubscribe link opens it with unsubscribe_token=<token> added; your page records the opt-out by POSTing that token to /unsubscribe/<token> on this API (idempotent). List-Unsubscribe keeps this API's one-click address, which records the opt-out itself and, opened in a browser, confirms it and then continues to your page. Omit to use the hosted page.

draft.topicIdstring

The topic the campaign is about (listTopics): it skips contacts who opted out of it, and its one-click unsubscribe opts out of this topic only. Not on a required notice.

draft.requiredNoticeboolean

A required notice: a message every recipient must get whatever their marketing choice, such as a change to terms, prices or taxes, never a promotion. It goes to everyone in the audience who is not suppressed, people who unsubscribed from marketing included, without an Unsubscribe link or List-Unsubscribe header, and is paced, limited and paused like any campaign. Only where an operator turned required notices on for the workspace (requiredNotices in getWorkspaceSettings); 403 REQUIRED_NOTICES_OFF otherwise. Sending or scheduling one needs confirmRequiredNotice. Turned off later, a launched notice pauses before releasing anyone more (pause reason REQUIRED_NOTICES_OFF) and is resumed or rescheduled only once they are on again. Resumed after a list-probe quarantine, it goes on to everyone captured for it (never deliveredOnly).

draft.htmlstring

Block HTML: h1-h3, p, ul/ol, blockquote, pre>code, hr, img, buttons, columns and styled sections with inline formatting. A constrained email-safe style attribute supports color, typography, spacing, borders, radius and dimensions; arbitrary CSS remains rejected. No wrappers, tables, class or id. Call getContentGuide in MCP or GET /v1/campaign-content-guide for the full vocabulary and examples.

Responses

200Success
Campaign
idrequiredstring
urlrequiredstring

Dashboard URL for opening this campaign. Drafts open in the editor; launched campaigns open in review.

revisionrequiredinteger
draftrequiredobject

Drafts may omit sender, subject, content and audience until review or send, except that domain-restricted keys must supply a From address on one of their domains. Content is block HTML (see html); the same form is what the dashboard composer reads and writes, so people and agents edit one document. Simple {{name}} personalization works in text and quoted href/alt attributes; values are HTML-escaped and rendered URLs are validated. Durable campaign preparation is bounded and runs in background jobs.

draft.namerequiredstring
draft.fromstring or string
draft.fromNamestring
draft.previewTextstring

Optional preheader text. Inserted as escaped hidden text into each outgoing HTML snapshot; draft HTML is unchanged. When set, supply HTML without its own duplicate preheader.

draft.replyTostring[]
draft.regionrequiredstring
draft.regionPinnedboolean

Regional MX only. False follows the From domain; the displayed region is a hint. A supplied region on create or a changed region on edit pins it. To unpin, pass false and omit region.

draft.subjectstring or string
draft.attachmentsstring[]

IDs of files uploaded first (uploadAttachment). One file is at most 8 MiB decoded when sent as base64 in JSON (POST /v1/attachments), or 25 MiB as raw bytes (POST /v1/attachments/upload, with the name URI-encoded in X-Nightmail-Filename and the type in Content-Type). One email carries at most 100 files and 25 MiB of them together, decoded. A workspace keeps at most 100 GiB of uploaded files. For anything larger, link to the file from the email.

draft.trackingboolean
draft.audienceobject
draft.defaultsobject
draft.unsubscribePageUrlstring

Your own unsubscribe or preference page: HTTPS, no user name, password, whitespace or unsubscribe_token parameter, at most 1,000 characters. The footer's Unsubscribe link opens it with unsubscribe_token=<token> added; your page records the opt-out by POSTing that token to /unsubscribe/<token> on this API (idempotent). List-Unsubscribe keeps this API's one-click address, which records the opt-out itself and, opened in a browser, confirms it and then continues to your page. Omit to use the hosted page.

draft.topicIdstring

The topic the campaign is about (listTopics): it skips contacts who opted out of it, and its one-click unsubscribe opts out of this topic only. Not on a required notice.

draft.requiredNoticeboolean

A required notice: a message every recipient must get whatever their marketing choice, such as a change to terms, prices or taxes, never a promotion. It goes to everyone in the audience who is not suppressed, people who unsubscribed from marketing included, without an Unsubscribe link or List-Unsubscribe header, and is paced, limited and paused like any campaign. Only where an operator turned required notices on for the workspace (requiredNotices in getWorkspaceSettings); 403 REQUIRED_NOTICES_OFF otherwise. Sending or scheduling one needs confirmRequiredNotice. Turned off later, a launched notice pauses before releasing anyone more (pause reason REQUIRED_NOTICES_OFF) and is resumed or rescheduled only once they are on again. Resumed after a list-probe quarantine, it goes on to everyone captured for it (never deliveredOnly).

draft.htmlstring
sourceTemplateIdrequiredstring or null
sourceTemplateRevisionrequiredinteger or null
staterequiredstring

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.

scheduledAtrequiredstring or null
archivedAtrequiredstring or null
createdAtrequiredstring
updatedAtrequiredstring
countsrequiredobject

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.totalrequiredinteger
counts.byStatusrequiredobject
deliveryrequiredobject or null

The current launch: null until the campaign is sent or scheduled, and cleared by a new revision.

delivery.totalrequiredinteger

Fixed recipient count once the audience is frozen (recipients expected while a large audience is being captured).

delivery.preparedrequiredinteger

Recipients whose message was validated.

delivery.expandedrequiredinteger

Recipients materialized as immutable email records.

delivery.canceledrequiredinteger

Recipients canceled before materialization. Materialized cancellations remain in counts.byStatus.canceled.

delivery.errorrequiredobject or null

Why the campaign failed or was canceled by the system.

delivery.pacingrequiredobject
delivery.consentrequiredobject or null

The consent source confirmed at launch, if any.

delivery.pausedAtrequiredstring or null
delivery.pauseReasonrequiredobject or null
delivery.deliveredOnlyrequiredboolean

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.waitingrequiredobject or null

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.stoppedDomainsobject[]

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.feedbackLagrequiredobject or null

Present while a campaign is preparing, sending, or paused when delivery feedback ingestion is at least 2 minutes behind.

sendEstimaterequiredobject or null

How long sending takes, for a draft or a campaign that has recipients left to release. Null for a finished or canceled campaign; lists leave it out.

sendEstimate.recipientsrequiredinteger or null

Recipients still to release: for a draft, the last audience count (previewCampaignAudience; null before one); once launched, those not released yet.

sendEstimate.ratePerSecondrequirednumber or null

The region's send rate the campaign plans at, per second, before its rate share; null until the region's quota was read.

sendEstimate.ramprequiredobject or null

Where the campaign is on the ramp. A Hosted sender's first large campaigns release in hourly steps that grow (1,000 an hour at first), moving to the next step once an hour at this one went out and its delivery results are in and clean; more than 3% bounces or more than 0.08% complaints (at least 2) in a step pause the campaign. The first step not already proven by the workspace's largest clean marketing hour of the last 30 days is where it starts, so an established sender skips it. Null when no ramp applies (self-hosted, your own AWS account, simulated mail, an established sender, or past the last step). Transactional mail never waits for it.

sendEstimate.secondsrequiredinteger or null

How long releasing the recipients left takes from when it starts (the campaign's last change, updatedAt, or scheduledAt): from the ramp, the daily cap (pacing.perDay), the rate share and the region's send rate. A draft is estimated without a daily cap at the full rate. An estimate: it assumes clean, prompt feedback and leaves out the list probe's wait, quota holds and other mail sharing the rate. Null when it cannot be told (no audience count or send rate yet).

sendEstimate.finishAtrequiredstring or null

A launched campaign: when its last recipient is expected to be released, as of its last change (updatedAt or scheduledAt, plus seconds). Null for a draft, while paused or failed, or when it cannot be told.

400, 401, 403, 404, 409, 413, 422, 429, 500, 503Request failed; use error.code and requestId to diagnose.
ApiError
errorrequiredobject
error.coderequiredstring
error.messagerequiredstring
error.requestIdrequiredstring
error.fieldstring
error.retryablerequiredboolean
error.resetAtstring

Next capacity change for a Hosted rolling send limit.

error.detailsobject[]

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

On a 403 permission refusal: what the request needs that this credential lacks. The Nightmail-Required-Permission header says the same.