CSV Exports

Two paths for exporting log data: (1) synchronous email-log CSV stream via signed token; (2) async API-request-log CSV emailed as an attachment because the table is too large to stream live.

Posthawk has two export pipelines depending on data size:

## Email logs (synchronous stream)

For `email_logs` (sent + received emails), the export is a streamed CSV download. You first request a signed token, then redirect the browser to the worker's CSV endpoint with that token. The browser receives the CSV as a file download.

This is what the dashboard's "Export CSV" button on the Logs page does.

Token TTL is 5 minutes and consumed on first use. Date range is capped at 31 days.

## API request logs (async, emailed)

The `request_logs` table records every authenticated HTTP request to the worker. It can hold tens of millions of rows for a busy workspace, so synchronous streaming would time out. Instead, the export is queued as a BullMQ job — the worker compiles the CSV and emails it to you as an attachment when ready (typically within a minute).

This is what the dashboard's "Export CSV" button on the Logs API tab does.
POST/export/tokenJWT

Request a signed token for an email-log CSV export. Token is valid for 5 minutes and consumed on first use.

ParameterTypeInDescription
typerequiredstringbody"sent" | "received" | "both"
dateFromrequiredstringbodyISO 8601 datetime (max 31 days back)
dateTorequiredstringbodyISO 8601 datetime
statusesstring[]bodyFilter by email_logs.status: queued, processing, sent, delivered, bounced, complained, failed
apiKeyIdstringbodyFilter sent emails to a specific API key (sent type only)
domainIdstringbodyFilter received emails to a specific domain (received type only)

Response

json
{ "token": "signed.jwt.string" }
GET/export/csv?token=...None

Download the CSV. Browser-redirected from the dashboard with the token from the previous step. Streams the CSV with Content-Disposition: attachment.

ParameterTypeInDescription
tokenrequiredstringquerySigned token from POST /export/token (5min TTL, consumed on first use)
POST/export/request-logsJWT

Queue an async request-logs export. The worker compiles the CSV and emails it to you as an attachment when ready. Date range capped at 31 days.

ParameterTypeInDescription
dateFromrequiredstringbodyISO 8601 datetime
dateTorequiredstringbodyISO 8601 datetime (max 31 days from dateFrom)
methodstringbodyHTTP method filter (GET, POST, PATCH, PUT, DELETE)
statusRangestringbody"2xx" | "4xx" | "5xx"

Response

json
{
  "success": true,
  "message": "Export queued. You will receive an email with the CSV attached when ready."
}