Newsletters
Automations
Send a sequence of emails to each contact who subscribes or does something in your app.
On this page
An automation sends a sequence of emails to each contact who enters it. A contact enters when its membership in the automation's audience becomes confirmed, or when your application records an event for it. Create one with POST /v1/automations and an Idempotency-Key header:
{
"audienceId": "audience_customers",
"name": "Trial onboarding",
"from": "hello@news.example.com",
"trigger": { "type": "event", "eventName": "trial_started" },
"segment": { "match": "all", "conditions": [{ "attribute": "plan", "operator": "equals", "value": "pro" }] },
"steps": [
{ "type": "send_email", "templateId": "template_welcome" },
{ "type": "wait", "minutes": 1440 },
{ "type": "exit_unless", "segment": { "match": "all", "conditions": [{ "attribute": "activated", "operator": "not_exists" }] } },
{ "type": "send_email", "templateId": "template_nudge" }
],
"reentry": "once"
}The trigger is one of these:
contact_subscribedstarts when a contact's membership in the audience becomes confirmed. That includes the API, the dashboard, an import and a double opt-in confirmation.eventstarts whenPOST /v1/eventsrecords an event witheventNamefor a confirmed member of the audience.
An automation has 1 to 20 steps, which run in order:
send_emailsends one newsletter copy. It takestemplateId,localizedTemplatesandvalueslike a broadcast. Templates readcontact.*, and for an event trigger they read the event's properties asevent.*.waitwaitsminutes, from 1 minute to 365 days.exit_unlessends the enrollment unless the contact still matchessegment, which works like a broadcast segment.
The optional segment on the automation is checked when a contact enters, and contacts that do not match are not enrolled. A contact has at most one active enrollment in an automation. With reentry: "once", the default, a contact enters an automation at most once. With reentry: "always", a contact enters again on each trigger after its previous enrollment finished.
States
An automation starts as a draft. POST /v1/automations/:automationId/activate makes it active, and it starts enrolling contacts. pause makes it paused, and archive makes it archived. Activate a paused automation to resume it. Archived is final.
| From | To |
|---|---|
draft | active, archived |
active | paused, archived |
paused | active, archived |
Any other move, such as pausing a draft, returns invalid_transition. Repeating the current state, such as activating an active automation, returns it unchanged.
You can change an automation with PATCH /v1/automations/:automationId only while it is a draft or paused. Other changes return automation_not_editable. The audience can change only before the first activation.
Activation freezes the steps, their templates and the tracking setting into a numbered version. Each enrollment runs the version it entered on to the end, so an edit and a new activation change only later enrollments. Activating unchanged content keeps the current version.
A paused automation enrolls nobody, and its enrollments wait at their current step. Activate it again, and they continue. Archiving ends every active enrollment with exit reason archived. Archiving the audience also ends every active enrollment of its automations, with exit reason audience_archived.
Send events
Record an event with POST /v1/events. Name the contact with contactId or email, but not both. The Idempotency-Key header is required. Use one key per real occurrence, such as the ID of the order or signup that caused the event. A retry with the same key and body returns the first result and enrolls nobody again. The same key with a different body returns idempotency_conflict.
{
"email": "ada@example.com",
"name": "trial_started",
"properties": { "plan": "Pro", "trialDays": "14" }
}The response lists the automations the event enrolled the contact into in enrolled. An event for a contact that is not a confirmed member of an automation's audience is recorded and enrolls nobody. An unknown contact returns not_found. Ternwire deletes events after 30 days. The enrollment keeps its copy of the properties.
How copies are sent
Each copy goes through the same consent, suppression and quota checks as a broadcast copy, with the same footer and unsubscribe link. A contact who unsubscribes, leaves the audience or is deleted exits at once, and no later copy reaches them. Each step of an enrollment is sent at most once, even when a step is retried.
When the workspace runs out of quota or can no longer send, Ternwire pauses the automation with pauseReason quota_exceeded or organization_blocked. Its enrollments wait where they are. Activate it again after you fix the cause.
POST /v1/automations/:automationId/test sends one send_email step as a test copy to up to 5 verified members of your workspace. Pass the step's zero-based index as step, an optional locale and sample event properties for a template that reads event.*. A test copy enrolls nobody.
Reports
GET /v1/automations/:automationId/stats returns how many contacts entered, are active, completed and failed, and how many exited for each reason. For each step of the current version it returns the copies sent and the unique opens and clicks. GET /v1/automations/:automationId/enrollments lists enrollments with each contact's step, next run time, state and exit reason. Filter with state or contactId.