Preview campaign audience
/v1/campaigns/{id}/audienceCounts 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.
Needs Audience & content: read on the whole workspace.
Example
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 --request GET \
--url 'https://nightmail.dev/v1/campaigns/resource_123/audience' \
--header "Authorization: Bearer $NIGHTMAIL_API_KEY"Parameters
idrequiredpath · stringreadinessquery · stringAlso review the send (readiness).
Responses
200Success
CampaignAudienceCountsLive 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.
matchedrequiredintegereligiblerequiredintegersuppressedrequiredintegerunsubscribedrequiredintegerriskyrequiredintegerContacts 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.
riskyByReasonrequiredobjectriskyByReason.invalidrequiredintegerriskyByReason.disposablerequiredintegerriskyByReason.typo_domainrequiredintegerriskyByReason.rolerequiredintegerriskyByReason.deadrequiredintegerriskyByReason.no_mail_domainrequiredintegertopicExcludedintegerWith 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.
approximatebooleanThe 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.
readinessobject or nullWith readiness=true: the send review of a marketing campaign with a sender; null for a required notice or a draft without a sender.
readiness.verdictrequiredstringready: 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.summaryrequiredstring or nullWhy, in one or two plain sentences, when a ramp is recommended or required.
readiness.reasonsrequiredobject[]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.findingsobject[]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.unavailablestringPresent 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.domainrequiredobjectreadiness.historyrequiredobjectreadiness.listrequiredobjectreadiness.sizeJumprequirednumber or nullThis send ÷ the largest campaign its domain sent in the last 90 days; null without one.
readiness.usualJumpnumber or nullThis send ÷ the workspace's usual day (history.workspace.usualDay); null without one.
readiness.planrequiredobject or nullThe recommended daily batches; null when one day covers everyone.
readiness.requiredrequiredobject 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.