Reference

API reference

Explore Ternwire API v1 endpoints, authentication, email request fields, limits, error responses, and the OpenAPI download.

On this page

The Ternwire public API uses JSON over HTTP under /v1. Authenticate with Authorization: Bearer YOUR_API_KEY. The OpenAPI JSON document defines request and response schemas for the endpoints below.

Base URL

https://ternwire.com/v1

The OpenAPI document names https://ternwire.com/v1 as its server, so a client generated from it needs no base URL. It also says which API key scope each operation needs (x-ternwire-scope), and its webhooks section describes the body of every webhook event.

Authentication and request scope

Keep keys on your server and grant only the scopes your integration needs. An em_test_ key sends test-mode email, which is never delivered to a real inbox. Domain administration requires a live key. Webhook and blocked-address administration accept either key mode with sending access. A key belongs to one workspace and can reach only that workspace's domains, messages, templates, and attachments.

A key can also be limited to some of the workspace's sending domains when you create it. Such a key sends only from those domains: a from on any other domain gets 422 with sender_domain_not_allowed. It can't manage domains or receiving addresses (403, api_key_domain_restricted), and it can't have the broadcasts:write or automations:write scopes, because broadcasts and automations send later from their own sender.

curl "https://ternwire.com/v1/domains" \
  --header "Authorization: Bearer $TERNWIRE_API_KEY"

GET /v1/me works with any key, whatever its scopes. It returns the workspace, the calling key's scopes, mode, domain limit and expiry, the plan, whether live sending is allowed and why not (sending.blockedBy), the recipients left this billing period and, on the free plan, today, and the AI template credits left. Call it first to learn what a key can do before you act with it.

A key with the api_keys:write scope can list, create and revoke keys through /v1/api-keys. It can only create or revoke keys with no more access than its own: only scopes it has, test mode if it is a test key, only its own sending domains if it is limited to some, and an expiry no later than its own. Anything more gets 403 with api_key_privilege_exceeded and names the field. A key can always revoke itself. No preset includes api_keys:write: an owner picks it under Custom on the API keys page. Keys made this way keep working after the key that made them is revoked, so revoke them too when you retire an integration.

Email request fields

POST /v1/emails needs a sender and at least one recipient across to, cc, and bcc, with at most 50 recipients in total. Supply subject and at least one of text or html, or use templateId and values. Use attachmentIds for uploaded, clean attachments. Duplicate recipients are rejected.

FieldTypeNotes
fromstringAn address on a verified sending domain.
to, cc, bccstring[]At least one recipient, and at most 50 across all three.
subjectstringRequired unless you send a template.
text, htmlstringAt least one, unless you send a template.
templateId, valuesstring, objectSend a saved template instead of a subject and body. values fills in its variables.
replyTostringOptional reply address.
attachmentIdsstring[]Clean attachments, at most 20.
tagsobjectYour own labels. Keys are up to 64 letters, digits, _ or -, and values up to 256 characters.
headersobjectCustom headers. Names must start with X-.

Send an Idempotency-Key header of 1-128 characters. Ternwire remembers the key for 7 days after it accepts the email, and a retry with the same key and body in that time returns the first answer without sending again. A successful acceptance returns 202 with the message ID, the queued state, and the acceptance time. The Emails API has every field and a request you can copy. Start with the complete quickstart.

Limits

LimitValue
Email requests10 a second per workspace. Newsletter emails sent one at a time with purpose: "marketing" have their own 5 a second. See rate limits.
Recipients per email50 across to, cc and bcc
Message size40 MB once encoded, attachments included
Attachments per email20, each up to 15 MB
Idempotency keysRemembered for 7 days
Webhook endpoints10 per workspace
Templates500 per workspace
Ternwire's test address10 recipients in any 24 hours, see sending before your domain is ready
Free plan100 recipients a day at first, then 500 a day after a clean first week. See pricing for every plan.

Rate limits

Each workspace can send 100 emails at once through POST /v1/emails, and after that 10 a second. Unused room builds back up at 10 a second until it reaches 100 again. Newsletter emails have their own, separate limit: 50 at once, then 5 a second.

Every response to a send carries three headers, so you can pace a batch before you reach the limit:

HeaderMeaning
RateLimit-LimitHow many emails can go at once when the limit is full: 100, or 50 for newsletter emails.
RateLimit-RemainingHow many more emails can go right now.
RateLimit-ResetSeconds until the limit is full again.

A request over the rate limit gets 429 with code: "rate_limited" and a Retry-After header in seconds. Wait that long, then send the same request again with the same idempotency key. To send a large batch, such as a day's receipts, keep each workspace under the per-second rate, for example with a queue that sends one email at a time. Broadcasts and automations are paced for you, so they never use up the rate for app email.

Available endpoints

Each group of endpoints has its own page with parameters, request fields, and request and response examples.

All 94 endpoints
MethodPathOperation
POST/v1/emailssubmitEmail
GET/v1/emailslistMessages
GET/v1/emails/{messageId}getMessage
POST/v1/templatescreateEmailTemplate
GET/v1/templateslistEmailTemplates
GET/v1/templates/{templateId}getEmailTemplate
PUT/v1/templates/{templateId}replaceEmailTemplate
DELETE/v1/templates/{templateId}deleteEmailTemplate
POST/v1/attachmentscreateAttachmentUploadSlot
GET/v1/attachments/{attachmentId}getAttachment
POST/v1/attachments/{attachmentId}/completecompleteAttachmentUpload
GET/v1/domainslistSendingDomains
POST/v1/domainscreateSendingDomain
GET/v1/domains/{domainId}getSendingDomain
DELETE/v1/domains/{domainId}deleteSendingDomain
GET/v1/domains/{domainId}/receiving-addresseslistReceivingAddresses
POST/v1/domains/{domainId}/receiving-addressescreateReceivingAddress
POST/v1/domains/{domainId}/receiving-addresses/checkcheckReceivingAddresses
PATCH/v1/domains/{domainId}/receiving-addresses/{addressId}updateReceivingAddress
DELETE/v1/domains/{domainId}/receiving-addresses/{addressId}deleteReceivingAddress
GET/v1/inbound-emailslistInboundEmails
GET/v1/inbound-emails/{inboundEmailId}getInboundEmail
GET/v1/inbound-emails/{inboundEmailId}/rawgetInboundEmailRaw
GET/v1/webhook-endpointslistWebhookEndpoints
POST/v1/webhook-endpointscreateWebhookEndpoint
PATCH/v1/webhook-endpoints/{endpointId}updateWebhookEndpoint
DELETE/v1/webhook-endpoints/{endpointId}deleteWebhookEndpoint
POST/v1/webhook-endpoints/{endpointId}/rotate-signing-secretrotateWebhookEndpointSigningSecret
GET/v1/webhook-attemptslistWebhookAttempts
GET/v1/webhook-attempts/{attemptId}getWebhookAttempt
POST/v1/webhook-attempts/{attemptId}/replayreplayWebhookAttempt
GET/v1/suppressionslistSuppressions
POST/v1/suppressionscreateSuppression
DELETE/v1/suppressions/{suppressionId}deleteSuppression
POST/v1/audiencescreateAudience
GET/v1/audienceslistAudiences
GET/v1/audiences/{audienceId}getAudience
PATCH/v1/audiences/{audienceId}updateAudience
POST/v1/audiences/{audienceId}/archivearchiveAudience
GET/v1/audiences/{audienceId}/exportexportAudience
POST/v1/audiences/{audienceId}/subscriptionsrequestSubscription
DELETE/v1/audiences/{audienceId}/subscriptions/{contactId}unsubscribeContact
POST/v1/contactsupsertContact
GET/v1/contactslistContacts
GET/v1/contacts/{contactId}getContact
DELETE/v1/contacts/{contactId}deleteContact
GET/v1/contact-import-sourceslistContactImportSources
POST/v1/contact-importscreateContactImport
GET/v1/contact-importslistContactImports
GET/v1/contact-imports/{importId}getContactImport
POST/v1/contact-imports/{importId}/applyapplyContactImport
GET/v1/contact-import-batches/{batchId}getContactImportBatch
POST/v1/contact-import-batches/{batchId}/applyapplyContactImportBatch
POST/v1/broadcastscreateBroadcast
GET/v1/broadcastslistBroadcasts
GET/v1/broadcasts/{broadcastId}getBroadcast
PATCH/v1/broadcasts/{broadcastId}updateBroadcast
POST/v1/broadcasts/{broadcastId}/sendsendBroadcast
POST/v1/broadcasts/{broadcastId}/previewpreviewBroadcast
POST/v1/broadcasts/{broadcastId}/testsendBroadcastTest
POST/v1/broadcasts/{broadcastId}/unscheduleunscheduleBroadcast
POST/v1/broadcasts/{broadcastId}/pausepauseBroadcast
POST/v1/broadcasts/{broadcastId}/resumeresumeBroadcast
POST/v1/broadcasts/{broadcastId}/cancelcancelBroadcast
GET/v1/broadcasts/{broadcastId}/recipientslistBroadcastRecipients
GET/v1/broadcasts/{broadcastId}/engagementgetBroadcastEngagement
GET/v1/broadcasts/{broadcastId}/ab-testgetBroadcastAbTest
POST/v1/broadcasts/{broadcastId}/ab-test/winnerpickBroadcastAbTestWinner
POST/v1/automationscreateAutomation
GET/v1/automationslistAutomations
GET/v1/automations/{automationId}getAutomation
PATCH/v1/automations/{automationId}updateAutomation
POST/v1/automations/{automationId}/activateactivateAutomation
POST/v1/automations/{automationId}/pausepauseAutomation
POST/v1/automations/{automationId}/archivearchiveAutomation
GET/v1/automations/{automationId}/statsgetAutomationStats
GET/v1/automations/{automationId}/enrollmentslistAutomationEnrollments
POST/v1/automations/{automationId}/testsendAutomationTest
POST/v1/eventscreateContactEvent
GET/v1/marketing-settingsgetMarketingSettings
PATCH/v1/marketing-settingsupdateMarketingSettings
GET/v1/tracking-settingsgetTrackingSettings
PATCH/v1/tracking-settingsupdateTrackingSettings
GET/v1/metricsgetDeliveryMetrics
GET/v1/megetCurrentAccount
GET/v1/api-keyslistApiKeys
POST/v1/api-keyscreateApiKey
DELETE/v1/api-keys/{apiKeyId}revokeApiKey
POST/v1/templates/renderrenderUnsavedTemplate
POST/v1/templates/{templateId}/renderrenderEmailTemplate
POST/v1/templates/generategenerateEmailTemplate
GET/v1/templates/generation-creditsgetTemplateGenerationCredits
POST/v1/domains/{domainId}/checkcheckDomain
GET/v1/domains/{domainId}/dns-setupgetDomainDnsSetup

Pagination

Every list returns one page in the same shape:

{
  "data": [],
  "page": { "nextCursor": "eyJjcmVhdGVkQXQiOi...", "hasMore": true }
}

Pass page.nextCursor as the cursor query parameter to get the next page, until page.hasMore is false. limit sets the page size, from 1 to 100, and defaults to 25. A cursor is opaque: pass it back unchanged and do not build one yourself.

Audiences, contacts, contact imports, broadcasts, broadcast recipients, automations and enrollments also repeat hasMore and nextCursor at the top level, where they first returned them. Those two fields are deprecated and will be removed in a later API version, so read page.

Templates, audiences, contacts, broadcasts and automations list newest first. A cursor these lists issued before they were ordered by creation time starts again at the first page.

Errors and retry decisions

Every error has a JSON body with the same fields. Branch on the code, not on the message text, which can change.

{
  "status": "invalid_request",
  "code": "invalid_request",
  "title": "Invalid request",
  "message": "Some fields in the request are missing or invalid.",
  "fields": { "subject": ["This field is required."] },
  "requestId": "req_3f2b1c4e-8a9d-4e1f-b6c7-2d5e8f9a0b1c"
}
FieldMeaning
codeThe error code, such as invalid_request or rate_limited. Branch on this.
statusThe same code, kept for clients written before code was on every error.
titleA short summary.
messageWhat went wrong and what to do, in plain English.
fieldsOnly on errors about the request body: each field that needs a change, with what to change.
requestIdThe same value as the X-Request-Id header.

Some errors add details, such as limit on a plan limit, requiredScope on a missing scope, or actualBytes and limitBytes on a message that is too large. Errors lists every code with what to do.

Each SDK raises one error type for API errors, with the HTTP status and the parsed body:

import { TernwireApiError } from "ternwire";

try {
  await client.submitEmail(email, "order-123-receipt");
} catch (error) {
  if (!(error instanceof TernwireApiError)) throw error; // a network failure
  const { httpStatus, code, message, fields } = error.parsed;
  console.error(httpStatus, code, message, fields, error.headers["x-request-id"]);
}

Every response carries an X-Request-Id header, such as req_3f2b1c4e-8a9d-4e1f-b6c7-2d5e8f9a0b1c, and every error body repeats it as requestId. Log it with each failed request and include it when you contact support, so the request can be found in Ternwire's logs. Requests made with an API key, rejected ones included, appear in the dashboard's Request log for 30 days. Search there for the request ID to see the route, status, error code and key.

StatusWhat to do
400Fix invalid input or duplicate recipients. fields says what to change.
401invalid_api_key: the key is missing, malformed, unknown, revoked or expired. Send a current key.
403missing_scope: the key works but lacks the scope the operation needs, named in requiredScope. Other 403 codes name a key mode or account setting to change, such as an operation that needs a live key.
402Check your plan or spending limit before retrying.
404Check the ID, and that it belongs to the key's workspace.
409Tell a changed-payload idempotency conflict apart from a request still in progress. Only retry the original payload, and follow Retry-After when provided.
413Make the message smaller.
422Fix the cause before retrying: a sending domain that isn't verified, a paused workspace, an inactive subscription, a blocked recipient, or a template or attachment that can't be used. From Ternwire's test address, also a recipient outside your workspace or a used-up daily allowance.
429, 5xxA 503 temporarily_unavailable means the request took too long on our side and was stopped. Honor Retry-After when present, see limits, and apply bounded backoff with the original idempotency key.

Do not automatically retry every failure with a new key. Use the accepted message ID to reconcile uncertainty, and read delivery states before you implement recovery.