List campaigns
/v1/campaignsReturns 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 · stringlimitquery · integerregionquery · stringstatequery · stringdraft: 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 · stringFalse lists active campaigns; true lists archived campaigns only.
searchquery · stringlistIdquery · stringOnly campaigns whose audience list is this one: a newsletter’s issues.
newsletterquery · stringtrue: 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[].idrequiredstringdata[].urlrequiredstringDashboard URL for opening this campaign. Drafts open in the editor; launched campaigns open in review.
data[].revisionrequiredintegerdata[].sourceTemplateIdrequiredstring or nulldata[].sourceTemplateRevisionrequiredinteger or nulldata[].staterequiredstringdraft: 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 nulldata[].archivedAtrequiredstring or nulldata[].createdAtrequiredstringdata[].updatedAtrequiredstringdata[].countsrequiredobjectCounts 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 nullThe current launch: null until the campaign is sent or scheduled, and cleared by a new revision.
data[].draftrequiredobjectdata[].statsrequiredobject or nullThe 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 null400, 401, 403, 404, 409, 413, 422, 429, 500, 503Request failed; use error.code and requestId to diagnose.
ApiErrorerrorrequiredobjecterror.coderequiredstringerror.messagerequiredstringerror.requestIdrequiredstringerror.fieldstringerror.retryablerequiredbooleanerror.resetAtstringNext 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.requiredobjectOn a 403 permission refusal: what the request needs that this credential lacks. The Nightmail-Required-Permission header says the same.