Mailpark
Guides

SDK and CLI

A typed TypeScript client for Node, Bun, Deno and edge runtimes, and a command-line tool for templates, tests and logs. Both wrap the same REST API.

Install

npm install mailpark

The client reads MAILPARK_API_KEY and MAILPARK_API_URL from the environment, or takes them as options.

import { Mailpark } from "mailpark";

export const mailpark = new Mailpark({
  apiKey: process.env.MAILPARK_API_KEY,
  baseUrl: "https://api.mailpark.io",
});
OptionDefault
apiKeyMAILPARK_API_KEYTest or live key.
baseUrlMAILPARK_API_URLFalls back to the local API, http://localhost:4000.
autoIdempotencytrueAdd a random Idempotency-Key to every write.
fetchglobal fetchBring your own, for tests or proxies.
headers{}Extra headers on every request.

Calls

Methods mirror the API reference, and every example there has a TypeScript tab. The last argument of every method takes { idempotencyKey, signal }.

ResourceMethods
emailssend, batch, list, get, explain
contactsupsert, list, get, update, delete
listslist, create, get, update, delete, contacts, addContacts, removeContacts
eventsrecord, list
eventTypeslist, get, create, update, delete
templateslist, get, create, update, upsert, delete, preview, addEssentials
broadcastsdraft, list, get, update, cancel, audiencePreview
sequencescreate, list, get, update, on, off, simulate, enrollments, stepCounts
webhookscreate, list, get, delete, test, deliveries, resend
domainsadd, list, get, verify, connect, remove
accountpauseMarketing
(top level)me, health, getStarted, activity, testInbox, request

Anything else is one mailpark.request(method, path, { body, query }) away.

Errors

Any non-2xx response throws a MailparkError with status, code, message, fix and, for validation errors, fields. A network failure throws one with code network_error. See errors.

Webhooks

verifyWebhook(rawBody, signatureHeader, secret) checks the signature and returns the parsed event. See verifying webhooks.

CLI

Every command accepts --json for scripts and agents, and --api-url to point at another server.

CommandDoes
mailpark login --key sk_test_… --email you@acme.devSave a key for this machine.
mailpark initSet up templates and an emails/ folder in your project.
mailpark templates pushPublish every emails/<key>.html as a new version.
mailpark test password-reset --to meSend a template to yourself.
mailpark inboxRead the test inbox.
mailpark logs --to jane@example.comSearch the send log.
mailpark explain msg_…Explain what happened to one email.
mailpark sequences simulate seq_…Fast-forward a sequence.
mailpark healthRates, trust level and usage.

Templates in your repo live in emails/<key>.html, with a header comment that templates push reads:

emails/trial-ending.html
<!--
key: trial-ending
type: marketing
subject: Your {{product_name}} trial ends in 3 days
-->
<html>…{{first_name}}…</html>