Automations

API reference for sending events that start automations, listing automations and adding contacts to one.

Using an AI agent? Just ask:“Tell Maillayer that [email protected] just started a pro trial.”Connect your agent →

Build automations on the canvas in the dashboard (see Automations), or design them here: the API creates, changes, turns on and pauses them. It also starts them for people, with events or by adding contacts directly.

Send an event#

POST/api/v1/events

Something happened for a contact in your app. Creates the contact if it doesn't exist, then starts every automation that's on with an An event happens trigger for this event name.

Body

  • emailstringrequired
    The contact's email address.
  • eventstringrequired
    1 to 100 letters, numbers, dots, dashes or underscores, like trial_started. Matched whatever the case.
  • propertiesobject
    Details of the event: strings, numbers, booleans or null. Usable in the automation's emails as {{ event.plan }}.
  • first_namestring
    Set or update the contact's first name.
  • last_namestring
    Set or update the contact's last name.
Request
curl https://maillayer.com/api/v1/events \
  -H "Authorization: Bearer $MAILLAYER_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "email": "[email protected]", "event": "trial_started",
        "properties": { "plan": "pro", "trial_days": 14 } }'
Response · 200
{
  "object": "event",
  "event": "trial_started",
  "contact_id": "5f1c…",
  "email": "[email protected]",
  "automations_started": [{ "id": "c76c…", "name": "Trial onboarding" }]
}

automations_started is empty when nothing is listening, or when the contact is unsubscribed, suppressed, already in the flow, or went through it before and re-entry is off. Sending the same event twice is safe.

List automations#

GET/api/v1/automations
Request
curl https://maillayer.com/api/v1/automations \
  -H "Authorization: Bearer $MAILLAYER_KEY"
Response · 200
{
  "data": [
    {
      "id": "c76c…",
      "object": "automation",
      "name": "Trial onboarding",
      "status": "active",
      "trigger": { "type": "event", "event": "trial_started" },
      "activated_at": "2026-12-04T11:43:47.725Z",
      "people": { "active": 182, "finished": 1204 }
    }
  ]
}

status is draft, active or paused. trigger.type is list, event, manual or date.

Create an automation#

POST/api/v1/automations

Saves a draft. Nothing is sent until you turn it on. The response says what's still missing in problems, and url opens it on the canvas.

Body

  • namestringrequired
    Shown in the dashboard.
  • triggerobjectrequired
    What starts it. See Triggers below.
  • stepsobject[]
    The flow, top to bottom. See Steps below.
  • fromstring
    Acme <[email protected]>. The domain must be verified to turn it on.
  • reply_tostring
    Where replies go.
  • allow_reentryboolean
    Whether someone can go through it again after finishing. Default false.

Triggers

triggerStarts when
{ "type": "list", "list": "Newsletter" }Someone is added to the list (name or id).
{ "type": "event", "event": "trial_started" }Your app sends this event.
{ "type": "manual" }You or your app add people to it.
{ "type": "date", "property": "trial_ends_at", "offset_days": -3, "hour": 9 }Days before (negative) or after a contact's date property, at that hour UTC. Defaults: 0 days, 9:00.

Steps

Every step can have an id of your own, like welcome; otherwise one is made up. A branch or an exit is the last step on its path: what comes after a branch goes in its yes and no arrays.

typeFields
emailsubject, preheader, html, or template (a template id or alias). Liquid works, including {{ event.plan }} for event properties.
waitamount and unit: minutes, hours or days.
branch_engagementemail_step_id (an email earlier on the path), check: opened or clicked, yes, no.
branch_conditionfield: list, property, country or status. key: the list or property name. op: is, is_not, contains or exists. value, yes, no.
list_add, list_removelist: a list name or id.
exitEnds this path.
Request
curl https://maillayer.com/api/v1/automations   -H "Authorization: Bearer $MAILLAYER_KEY"   -H "Content-Type: application/json"   -d '{
    "name": "Welcome series",
    "trigger": { "type": "list", "list": "Newsletter" },
    "from": "Acme <[email protected]>",
    "steps": [
      { "id": "welcome", "type": "email", "subject": "Welcome, {{ first_name | default: "there" }}",
        "html": "<p>Thanks for joining.</p>" },
      { "type": "wait", "amount": 2, "unit": "days" },
      { "type": "branch_engagement", "email_step_id": "welcome", "check": "opened",
        "yes": [ { "type": "email", "subject": "Three tips to start", "html": "<p>…</p>" } ],
        "no":  [ { "type": "email", "subject": "In case you missed it", "html": "<p>…</p>" } ] }
    ]
  }'
Response · 201
{
  "id": "0edd…",
  "object": "automation",
  "name": "Welcome series",
  "status": "draft",
  "trigger": { "type": "list", "list": "Newsletter" },
  "from": "Acme <[email protected]>",
  "reply_to": null,
  "allow_reentry": false,
  "steps": [ { "id": "welcome", "type": "email", … }, … ],
  "ready_to_turn_on": true,
  "problems": [],
  "stats": null,
  "url": "https://maillayer.com/automations/0edd…"
}

problems lists what keeps it from being turned on, like { "step": "sender", "message": "Pick who it's from." }. step is a step id, or trigger, sender or flow.

Get an automation#

GET/api/v1/automations/:id

The same shape as above. Once it has been on, stats has started, in_flow, completed, exited and, per step id, sent, opened, clicked, yes, no and here (people on that step now).

Change an automation#

PATCH/api/v1/automations/:id

Takes the same fields as create; only the ones you send change. steps replaces the whole flow, so get it, edit it and send it back. Keep each step's id so its people and numbers stay with it. An email step sent without html keeps the content it has.

You can change an automation that's on. People on a step you removed leave the flow, and a new trigger starts from now. It has to stay complete while it's on: otherwise you get 422 incomplete_flow.

Turn on#

POST/api/v1/automations/:id/activate

Turns it on, or back on after a pause. It needs everything filled in, a verified From domain and an approved account; otherwise you get 422 incomplete_flow or 403 approval_required. For a list trigger, send { "include_existing": true } to start it for everyone already on the list too. Otherwise only people added from now on start it.

Pause#

POST/api/v1/automations/:id/pause

Nobody new starts and nobody moves on. Turning it back on picks up where everyone was, including people added to a list while it was paused.

Delete an automation#

DELETE/api/v1/automations/:id

Everyone in it stops, and emails it queued but hasn't sent are dropped and their plan emails returned.

Add contacts to an automation#

POST/api/v1/automations/:id/enroll

Starts an automation that's on for existing contacts, whatever its trigger. Give emails, a list, or both. Returns 409 automation_off if it isn't on.

Body

  • emailsstring[]
    Up to 1,000 contact emails. Emails that aren't contacts are ignored.
  • liststring
    A list name or id: everyone on it starts.
Request
curl -X POST https://maillayer.com/api/v1/automations/c76c…/enroll \
  -H "Authorization: Bearer $MAILLAYER_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "list": "Beta testers" }'
Response · 200
{ "automation_id": "c76c…", "matched": 240, "started": 231, "skipped": 9 }

Skipped contacts are unsubscribed, suppressed, flagged, already in it, or went through it before with re-entry off.