NightmailDocs
Docs

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.

Needs Audience & content: read for the sender domain.

Example

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 --request GET \
  --url 'https://nightmail.dev/v1/campaigns' \
  --header "Authorization: Bearer $NIGHTMAIL_API_KEY"

Parameters

cursorquery · string
limitquery · integer
regionquery · string
statequery · string

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.

archivedquery · string

False lists active campaigns; true lists archived campaigns only.

searchquery · string
listIdquery · string

Only campaigns whose audience list is this one: a newsletter’s issues.

newsletterquery · string

true: only campaigns whose audience list is a newsletter. false: only the others, with no list or a list that is not a newsletter.

Responses

200Success
datarequiredobject[]
data[].idrequiredstring
data[].urlrequiredstring

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

data[].revisionrequiredinteger
data[].sourceTemplateIdrequiredstring or null
data[].sourceTemplateRevisionrequiredinteger or null
data[].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.

data[].scheduledAtrequiredstring or null
data[].archivedAtrequiredstring or null
data[].createdAtrequiredstring
data[].updatedAtrequiredstring
data[].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.

data[].deliveryrequiredobject or null

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

data[].draftrequiredobject
data[].statsrequiredobject or null

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.

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