L Linet Developers
Home / Journeys / Automations
Journey 08 · Automations

When something happens, do something: automations

An automation watches one kind of change (an item updated, a document issued), checks it against your conditions, and then sends a mail or an SMS, calls one of your webhooks, or updates a field. You build it on the Automations screen or through API v2, try it on a real record without sending anything, and read its run log afterwards.

Platinum, admins only. An API key needs automations:read / automations:write by name: * does not grant them, because an automation sends messages and changes records.

The shape of an automation

A trigger, conditions, and up to ten actions run in order:

{
  "name": "Thank-you SMS on an invoice-receipt",
  "trigger": { "event": "document.issued" },
  "conditions": { "match": "all", "rules": [
    { "field": "type_id", "op": "eq", "value": 320 },
    { "field": "total", "op": "gt", "value": 0 }
  ]},
  "actions": [
    { "type": "sms", "template_id": 4, "to": "recipient" },
    { "type": "webhook", "webhook_id": "wh_8d1e…" }
  ]
}

POST /api/v2/automations with that body creates it (201, id au_…). Everything is checked against the catalogue first: a wrong event, field, operator, template or webhook is a 422 naming the exact place, e.g. actions.0.template_id.

Triggers and conditions

The triggers are the webhook events, plus document.created (a document's first save, a draft included). Conditions can also read the record's custom fields, as custom.<key>. GET /api/v2/automations/catalogue lists them, each with its fields (in API v2 names, with their type) and the actions it allows.

OperatorMatches when the field…
eq, neequals / does not equal the value: numbers as numbers, text ignoring case
lt, gt, lte, gteis less / greater (or equal)
contains, starts_withcontains / starts with the text, ignoring case
empty, not_emptyhas no value / has one
changedchanged in this save (an .updated event); with a value, changed to it

match: "all" needs every rule, "any" one of them. No rules: every event.

Actions

TypeSettingsWhat it does
mailtemplate_id (optional), to: recipient or an address, attach_pdfThe document's mail, rendered from a mail template, the PDF attached. Document events only.
smstemplate_id, to: recipient or a numberThe SMS template, rendered for the document. Document events only.
webhookwebhook_idOne of your v2 webhooks is sent the event: signed, retried, in its delivery log.
update_fieldfield, valueSets the record's field (the value may hold {{sku}}-style fields of the record). The record's own rules apply.
make_documenttype_id, issueMakes a document of that type from the triggering one, referencing it: a draft unless issue. Document events only.
notifyusers, role, subject, textMails your staff (chosen users, everyone in a role, or both), the text filled with the record's fields.

Try it before you turn it on

POST /api/v2/automations/{id}/test with {"record_id": 1234} sends and writes nothing. It answers whether the conditions match that record now, and what each action would do: the rendered mail or SMS and who it goes to, the webhook's URL, a field's old and new value. Add "dry_run": false to run the actions for real, once.

When it runs, and the run log

QuestionAnswer
When?From the queue, seconds after the save is committed. A save that is rolled back runs nothing.
Can an automation set off another?No. What an automation writes never triggers automations, so two rules cannot loop.
A failed action?Stops the actions after it; the run is failed with the reason. A webhook action is retried as webhooks are.
Limits?50 automations per company; each runs at most 1,000 times an hour (the rest are logged as skipped).
Where do I see what happened?GET /api/v2/automations/{id}/runs: newest first, 90 days, each action's result.