Get metrics
/v1/metricsOperational created-cohort metrics, not invoicing or provider reputation. Dashboard sessions may receive a cached result until the workspace creates an email or records an email event (quantized to 10-second buckets during high-volume sending), or for up to 60 seconds, and compute at most 30 such Overview reads a minute: past that they get their last result (cache header stale) or 429 DASHBOARD_RATE_LIMITED. API keys, MCP and agent tokens always get fresh results. Selects emails created in [from,to), scoped by email region and stream. to defaults to now and from to 24 hours (granularity=10m) or 30 days before to; from equal to to is an empty window. Outcomes use current email state and all recorded events, including events after to; this is not a historical state snapshot. Each outcome counts distinct emails, so replays do not inflate counts and outcomes may overlap. Accepted (bucket sent) means evidence of provider acceptance, not merely queued/created. Daily UTC creation buckets contain count=created emails. Granularity defaults to day; granularity=hour returns hourly UTC creation buckets and granularity=10m returns 10-minute UTC creation buckets (within the last 6 days) with canonical ISO dates, while preserving daily buckets and totals. Absent buckets mean zero created emails and zero outcomes; no moving averages are applied. Engagement is observed, not verified human activity. 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 { getMetrics } from '@nightmail/sdk';
const client = createClient({
baseUrl: 'https://nightmail.dev',
auth: scheme => scheme.scheme === 'bearer'
? process.env.NIGHTMAIL_API_KEY
: undefined,
});
const result = await getMetrics({
client,
throwOnError: true,
});
console.log(result.data);curl --request GET \
--url 'https://nightmail.dev/v1/metrics' \
--header "Authorization: Bearer $NIGHTMAIL_API_KEY"Parameters
regionquery · stringfromquery · stringtoquery · stringstreamquery · stringgranularityquery · stringincludequery · stringComma-separated extras computed in the same statement: previous (totals for the window of equal length ending at from) and streams (totals per stream for the window, ignoring the stream filter).
Responses
200Success
Metricsbasisrequiredstringfromrequiredstringtorequiredstringregionrequiredstring or nullstreamrequiredstring or nulltotalsrequiredobjecttotals.emailsrequirednumbertotals.acceptedrequirednumbertotals.deliveredrequirednumbertotals.bouncedrequirednumbertotals.complainedrequirednumbertotals.openedrequirednumbertotals.clickedrequirednumbertotals.failedrequirednumbertotals.deliveryDelayedrequirednumbertotals.simulatedrequirednumberdailyrequiredobject[]daily[].daterequiredstringdaily[].countrequirednumberdaily[].sentrequirednumberdaily[].deliveredrequirednumberdaily[].bouncedrequirednumberdaily[].complainedrequirednumberhourlyobject[]hourly[].daterequiredstringhourly[].countrequirednumberhourly[].sentrequirednumberhourly[].deliveredrequirednumberhourly[].bouncedrequirednumberhourly[].complainedrequirednumbertenMinuteobject[]tenMinute[].daterequiredstringtenMinute[].countrequirednumbertenMinute[].sentrequirednumbertenMinute[].deliveredrequirednumbertenMinute[].bouncedrequirednumbertenMinute[].complainedrequirednumberpreviousobjectPresent with include=previous.
previous.fromrequiredstringprevious.torequiredstringprevious.totalsrequiredobjectstreamsobjectPresent with include=streams.
streams.transactionalrequiredobjectstreams.marketingrequiredobject400, 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.