API Reference

MergeMail exposes a REST API for all core platform operations. The full API is documented in OpenAPI 3.1 format.

Authentication

All API endpoints (except /api/webhooks/paystack) require a Bearer token in the Authorization header. Obtain a token by authenticating via Supabase (the token is the Supabase JWT).

Authorization: Bearer <your-supabase-jwt>

In SvelteKit, the JWT is available from the Supabase session:

const { data: { session } } = await supabase.auth.getSession();
const token = session?.access_token;

Base URL

https://your-domain.vercel.app/api

Endpoints Overview

MethodPathDescription
GET/meGet current user profile
GET/credits/balanceGet credit wallet balance
GET/credits/transactionsList credit ledger entries
GET/credit-packagesList active credit packages
POST/payments/initializeInitialize a Paystack payment
GET/payments/{reference}Get payment order status
GET/datasetsList datasets
POST/datasetsUpload and create a dataset
GET/datasets/{id}Get dataset details
DELETE/datasets/{id}Delete a dataset
GET/datasets/{id}/rowsGet paginated dataset rows
GET/templatesList document templates
POST/templatesUpload a document template
GET/templates/{id}Get template details
PATCH/templates/{id}Update template metadata
DELETE/templates/{id}Delete a template
GET/campaignsList campaigns
POST/campaignsCreate a new campaign
GET/campaigns/{id}Get campaign details
POST/campaigns/{id}/startStart a campaign
POST/campaigns/{id}/pausePause a running campaign
POST/campaigns/{id}/resumeResume a paused campaign
POST/campaigns/{id}/cancelCancel a campaign
GET/campaigns/{id}/reportGet delivery report
POST/smtp/testTest SMTP configuration
POST/webhooks/paystackPaystack webhook (no auth)
POST/internal/dispatchInternal: dispatch next email job

Common Response Format

All endpoints return JSON with a consistent envelope:

{"success": true, "data": { ... }}

Error responses:

{"success": false, "error": "Human-readable message", "code": "ERROR_CODE"}

Rate Limiting

There is currently no strict rate limit on individual API calls. Campaign dispatch throughput is limited by your SMTP server's sending rate. Abuse of the API may result in account suspension per the Acceptable Use Policy.

Notes on Internal Endpoints

The POST /internal/dispatch endpoint is used by the campaign dispatch worker (Vercel cron or manual trigger). It requires the internal CRON_SECRET header rather than a user Bearer token. Do not call this endpoint directly unless you are building custom dispatch automation.