List sent and received mail together
/v1/logsSent and received mail in one list, newest first, with an opaque cursor bound to the filters. Sent mail is what listEmails returns (keys restricted to domains see their own domains); received mail is what listInboundMessages returns for the same credential: administrators see every received message, including unrouted mail, with delivery details; dashboard members see mail on receiving addresses; other credentials get sent mail only. kind, campaignId and a sent-mail status filter sent mail and leave received mail out; status=received or status=spam filter received mail and leave sent mail out. 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 for the sender domain.
Example
import { createClient } from '@nightmail/sdk/client';
import { listLogs } from '@nightmail/sdk';
const client = createClient({
baseUrl: 'https://nightmail.dev',
auth: scheme => scheme.scheme === 'bearer'
? process.env.NIGHTMAIL_API_KEY
: undefined,
});
const result = await listLogs({
client,
throwOnError: true,
});
console.log(result.data);curl --request GET \
--url 'https://nightmail.dev/v1/logs' \
--header "Authorization: Bearer $NIGHTMAIL_API_KEY"Parameters
cursorquery · stringlimitquery · integerdirectionquery · stringsearchquery · stringAt least 3 characters: a shorter term is refused with 422 VALIDATION_FAILED. Sent mail: a literal, case-insensitive substring of the sender, recipients, subject or IDs. Received mail: a full-text match on sender, recipients, subject and body.
statusquery · stringA sent-mail status lists sent mail only. received lists received mail that is not flagged as spam; spam lists received mail flagged as spam (spam is visible to administrators only, so dashboard members get none). Either leaves sent mail out, and is refused (403) to credentials that cannot read received mail, like direction=received.
kindquery · stringSent mail only; received mail is left out when set.
campaignIdquery · stringSent mail only; received mail is left out when set.
regionquery · stringfromquery · stringMail created (sent) or received at or after this instant.
toquery · stringMail created (sent) or received before this instant.
countsquery · stringtrue adds counts: how many emails match each status and kind for these filters between from and to (all retained mail without them), whatever the cursor and limit. Counts that take longer than 2 seconds are refused with 422 READ_TOO_LARGE: narrow from and to.
Responses
200Success
LogPagedatarequiredobject[]data[].idrequiredstringEmail ID for sent mail (getEmail); message ID for received mail (getInboundMessage).
data[].directionrequiredstringdata[].untrustedContentrequiredbooleanReceived mail and sent mailbox replies can contain external sender content.
data[].atrequiredstringWhen the email was created (sent) or received.
data[].statusrequiredstringSent: the email status, or scheduled for a send waiting for its time (getEmail reads it as queued with scheduled true). Received: received, or spam when flagged (spam is shown to administrators only).
data[].fromrequiredobjectdata[].torequiredstring[]Sent: the To recipients (at most 20). Received: the addresses in the To header (at most 20).
data[].toCountrequiredintegerTotal To recipients (may exceed to.length when shortened).
data[].subjectrequiredstringdata[].streamrequiredstring or nullSent mail only.
data[].campaignIdrequiredstring or nulldata[].scheduledAtrequiredstring or nullSent mail that is scheduled: when it goes (UTC). Null for received mail.
data[].simulatedrequiredbooleanSent through the SES mailbox simulator. Always false for received mail.
data[].attachmentCountrequiredinteger or nullReceived mail only.
data[].threadIdrequiredstring or nullThe conversation (getInboundThread): every received email's, and a sent email's when it is a reply from a receiving address or inbox, or its In-Reply-To named a stored message its sender could read. Null when the caller can read none of the conversation's received or stored messages, and for credentials that cannot read received mail.
data[].threadCountrequiredinteger or nullMessages in that conversation the caller can read, this one included; null without threadId.
data[].addressesrequiredarray or nullReceived mail only: the receiving addresses it was delivered to that the caller can read. Empty for unrouted mail.
data[].regionrequiredstring or nullNull for received mail unless the caller is an administrator.
data[].envelopeTorequiredarray or nullReceived mail, administrators only: the SMTP envelope recipients (at most 20).
data[].envelopeToCountrequiredinteger or nullReceived mail, administrators only: total SMTP envelope recipients.
nextCursorrequiredstring or nullreceivedrequiredbooleanWhether received mail is included: false for direction=sent, with a sent-only filter, or when the credential cannot read inbound mail.
countsobjectWith counts=true only.
counts.statusrequiredobjectEmails per status (sent statuses, received and spam) between from and to, with every filter but status. A status with none is left out.
counts.kindrequiredobjectSent emails per kind between from and to, with every filter but kind.
counts.cappedrequiredobjectAlways false: the counts are exact. Kept for compatibility from when each direction counted at most its 50,000 newest emails.
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.