Get campaign stats
/v1/campaigns/{id}/statsLifetime campaign delivery and unique open/click statistics, progress, tracking setting and rates with numeric numerators/denominators. Counts distinct emails across all stored feedback, not event occurrences. Delivery/bounce/complaint rates use accepted emails; open/click rates use delivered emails. Both rate counts exclude simulated emails. Rates are fractions, null for zero denominators; engagement rates are also null with tracking disabled. Delivered means receiving-server acceptance, not inbox placement. Engagement includes bots/privacy proxies. Done means dispatch finished; asynchronous feedback can still change totals. A campaign of at least 20,000 recipients is counted in the background: about once a minute while it sends (every few minutes for the largest, so counting stays a small share of the database's time), once more when it finishes, and again when read more than 10 minutes later if anything changed. Its figures are the last count, so they can be minutes old; computedAt says when. A finished campaign keeps its figures after its emails leave the 30-day history. Each statement stops after 5 seconds: a request that needs longer is refused with 422 READ_TOO_LARGE. Narrow the dates or filters.
Needs Sent mail: read on the whole workspace.
Example
import { createClient } from '@nightmail/sdk/client';
import { getCampaignStats } from '@nightmail/sdk';
const client = createClient({
baseUrl: 'https://nightmail.dev',
auth: scheme => scheme.scheme === 'bearer'
? process.env.NIGHTMAIL_API_KEY
: undefined,
});
const result = await getCampaignStats({
client,
path: {
"id": "resource_123"
},
throwOnError: true,
});
console.log(result.data);curl --request GET \
--url 'https://nightmail.dev/v1/campaigns/resource_123/stats' \
--header "Authorization: Bearer $NIGHTMAIL_API_KEY"Parameters
idrequiredpath · stringResponses
200Success
CampaignStatsLifetime campaign statistics, with no date cutoff or pagination. Done means dispatch finished, not delivery finished. Feedback is asynchronous; missing engagement does not prove nobody read or clicked. Simulated outcomes are never evidence of real delivery.
idrequiredstringnamerequiredstringstaterequiredstringdraft: 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.
trackingrequiredbooleancountsrequiredobjectCounts 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.totalrequiredintegercounts.byStatusrequiredobjectdeliveryrequiredobject or nullThe current launch: null until the campaign is sent or scheduled, and cleared by a new revision.
delivery.totalrequiredintegerFixed recipient count once the audience is frozen (recipients expected while a large audience is being captured).
delivery.preparedrequiredintegerRecipients whose message was validated.
delivery.expandedrequiredintegerRecipients materialized as immutable email records.
delivery.canceledrequiredintegerRecipients canceled before materialization. Materialized cancellations remain in counts.byStatus.canceled.
delivery.errorrequiredobject or nullWhy the campaign failed or was canceled by the system.
delivery.pacingrequiredobjectdelivery.consentrequiredobject or nullThe consent source confirmed at launch, if any.
delivery.pausedAtrequiredstring or nulldelivery.pauseReasonrequiredobject or nulldelivery.deliveredOnlyrequiredbooleanAfter 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 nullWhy 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 nullPresent while a campaign is preparing, sending, or paused when delivery feedback ingestion is at least 2 minutes behind.
totalsrequiredobjectLifetime distinct email counts from current state and stored events; outcomes overlap. Accepted excludes simulated mail; other outcomes include simulated events for simulated mail. Opens and clicks include bots and privacy proxies. Failed means rejected or rendering failed; suppressed, canceled and uncertain mail remain in counts.byStatus.
totals.acceptedrequiredintegertotals.deliveredrequiredintegertotals.bouncedrequiredintegertotals.complainedrequiredintegertotals.openedrequiredintegertotals.clickedrequiredintegertotals.failedrequiredintegertotals.deliveryDelayedrequiredintegertotals.simulatedrequiredintegerratesrequiredobjectrates.deliveryrequiredobjectDelivered / accepted. Receiving-server acceptance, not inbox placement.
rates.bouncerequiredobjectBounced / accepted.
rates.complaintrequiredobjectComplained / accepted.
rates.openrequiredobjectUnique opened emails / delivered.
rates.clickrequiredobjectUnique clicked emails / delivered, not click-to-open rate.
computedAtrequiredstringWhen counts, totals and rates were counted: they include every change made before then. state and delivery are always current.
400, 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.