Reference

Emails API

Submit an email, list sent messages, and check one message's delivery state.

On this page

Every request needs Authorization: Bearer with an API key. Errors use the shapes and codes in Errors and retry decisions. The OpenAPI document has the full schemas.

Submit email

POST /v1/emails (submitEmail)

Accepts an email for delivery and returns its message ID at once. Delivery happens in the background: read it with getMessage or receive webhook events. Every request needs an Idempotency-Key header: reuse the key when retrying a request whose outcome you don't know, and the API returns the first result instead of sending again. Send either subject with html and/or text, or a saved templateId with values.

A body with purpose "marketing" sends one email to a confirmed subscriber and needs the marketing:send scope and a live key. Its single to address must be the contact's own, and cc, bcc and listManagement must be empty because Ternwire adds the unsubscribe headers and footer.

Needs an API key with the send scope.

Headers

NameTypeRequiredNotes
Idempotency-KeystringYesAt most 128 characters.

Request body

NameTypeRequiredNotes
fromstringYesSender address on a verified domain, optionally with a display name: Acme Shop <hello@acme.com>. Quote a name that has commas or other punctuation. At most 800 characters.
tostring[]Yes, unless cc or bcc is setAt most 50 recipients across to, cc and bcc.
ccstring[]NoAt most 50 recipients across to, cc and bcc.
bccstring[]NoAt most 50 recipients across to, cc and bcc.
replyTostringNoThe address replies go to, when it is not the sender. Email address. At most 320 characters.
attachmentIdsstring[]NoAttachments uploaded with createAttachmentUploadSlot whose scan came back clean. At most 20 items.
tagsobjectNoYour own labels, such as { "order": "123" }. Keys are up to 64 letters, digits, _ or -, and values up to 256 characters.
listManagementobjectNoAdds unsubscribe headers: { "unsubscribe": "https://...", "unsubscribePost": "List-Unsubscribe=One-Click" }. One-click needs an https URL.
headersobjectNoCustom headers, such as { "X-Order-Id": "123" }. Names must start with X-. Values are up to 998 characters.
subjectstringYes, unless you send a templateAt most 998 characters.
htmlstringYes, unless text is set or you send a templateAt most 5,000,000 characters.
textstringYes, unless html is set or you send a templateAt most 5,000,000 characters.
trackingobjectNoTurns open or click tracking on or off for this email only. Tracking changes only the HTML part.
templateIdstringNoSend a saved template instead of a subject and body.
valuesobjectNoData for the template, such as { "first_name": "Ada" }.
purposestringNoLeave it out for app email. Set it to marketing to send one newsletter email to a contact, with audienceId and contactId.
audienceIdstringNoWith purpose: "marketing": the audience the contact belongs to.
contactIdstringNoWith purpose: "marketing": the contact to send to.
curl --request POST "https://ternwire.com/v1/emails" \
  --header "Authorization: Bearer $TERNWIRE_API_KEY" \
  --header "Idempotency-Key: submitEmail-001" \
  --header "Content-Type: application/json" \
  --data '{
    "from": "notifications@yourdomain.com",
    "to": [
      "ada@example.com"
    ],
    "subject": "Your receipt",
    "text": "Thanks for your order."
  }'

List messages

GET /v1/emails (listMessages)

Lists emails accepted for this workspace, newest first, one page at a time, with each one's overall state. Pass nextCursor back as cursor for the next page.

Needs an API key with the send scope.

Query parameters

NameTypeRequiredNotes
cursorstringNo
limitintegerNoFrom 1 to 100. Default 25.
statestringNoOne of accepted, queued, held, submitting, submitted, submission_unknown, failed.
subjectstringNoAt most 200 characters.
recipientstringNoA complete address matches recipients with exactly that address, in any case. Part of an address matches recipients whose address contains it, which is slower. At most 320 characters.
acceptedFromstringNoISO 8601 date and time.
acceptedTostringNoISO 8601 date and time.
curl --request GET "https://ternwire.com/v1/emails" \
  --header "Authorization: Bearer $TERNWIRE_API_KEY"

Get message

GET /v1/emails/{messageId} (getMessage)

Returns one email with the delivery state of each recipient, and opens and clicks when tracking was on.

Needs an API key with the send scope.

Path parameters

NameTypeRequiredNotes
messageIdstringYes
curl --request GET "https://ternwire.com/v1/emails/{messageId}" \
  --header "Authorization: Bearer $TERNWIRE_API_KEY"

Get tracking settings

GET /v1/tracking-settings (getTrackingSettings)

Whether transactional email records opens and clicks. Needs the send scope. Broadcasts and automations use the marketing settings instead.

curl --request GET "https://ternwire.com/v1/tracking-settings" \
  --header "Authorization: Bearer $TERNWIRE_API_KEY"

Update tracking settings

PATCH /v1/tracking-settings (updateTrackingSettings)

Turns open and click tracking on or off for transactional email accepted from now on, through the API or SMTP. Both are off until changed. A send can override them with its tracking field. In the EU, tracking may need each recipient's consent.

Needs an API key with the send scope.

Request body

NameTypeRequiredNotes
openTrackingbooleanNoAdd a 1x1 image to the HTML part of each email, which records when the email is opened.
clickTrackingbooleanNoSend each http and https link in the HTML part through a Ternwire redirect that records the click.
curl --request PATCH "https://ternwire.com/v1/tracking-settings" \
  --header "Authorization: Bearer $TERNWIRE_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "openTracking": false,
    "clickTracking": false
  }'