NightmailDocs
Docs

Get campaign stats

get/v1/campaigns/{id}/stats

Lifetime 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 · string

Responses

200Success
CampaignStats

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

idrequiredstring
namerequiredstring
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.

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

totalsrequiredobject

Lifetime 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.acceptedrequiredinteger
totals.deliveredrequiredinteger
totals.bouncedrequiredinteger
totals.complainedrequiredinteger
totals.openedrequiredinteger
totals.clickedrequiredinteger
totals.failedrequiredinteger
totals.deliveryDelayedrequiredinteger
totals.simulatedrequiredinteger
ratesrequiredobject
rates.deliveryrequiredobject

Delivered / accepted. Receiving-server acceptance, not inbox placement.

rates.bouncerequiredobject

Bounced / accepted.

rates.complaintrequiredobject

Complained / accepted.

rates.openrequiredobject

Unique opened emails / delivered.

rates.clickrequiredobject

Unique clicked emails / delivered, not click-to-open rate.

computedAtrequiredstring

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