Automations
Rules that run on their own in a Brainerce store. The model (event, trigger, filter, steps, actions, runs), live values versus facts, how a run ends, limits by plan, the safety model, and the four ways to build one.
An automation is a rule a store runs on its own: a trigger (something happened, or the clock struck), an optional filter (only some of those events), then steps (conditions, waits, lookups, and actions that change the store or message someone).
trigger -> filter -> steps
order.paid@1 total >= 500 [ add_customer_tags@1, add_order_tags@1 ]Automations are a paid feature. FREE has none. PRO allows 10 active automations and 5,000 actions a month, GROWTH 25 and 50,000, ENTERPRISE is by agreement. See Limits and plans.
Not the same thing as the built-in email sequences. Abandoned-cart recovery, the welcome series and similar fixed flows are configured under Email. An automation is a rule you author. The two can overlap (see
RECOVERY_EMAIL_ACTIVEbelow), and they do not share settings.
The model
Event
Every change an automation can react to is recorded as an event: a small, immutable snapshot of what happened. Events are written in the same database transaction as the change itself, so an automation never misses one and never sees a change that rolled back. An event has a type (order.paid), an entity (the order id), an origin (who made the change) and facts (a fixed set of fields about the change).
Trigger
A definition names one trigger by a versioned id, for example order.paid@1. Use the newest version of a trigger for new work (product.updated@2, not @1).
| Family | Triggers |
|---|---|
| Orders | order.created@1, order.paid@1, order.cancelled@1, order.fulfilled@1, order.delivered@1, order.refunded@1, order.edited@1, order.field_set@1 |
| Returns | return.requested@1, return.approved@1, return.declined@1, return.received@1, return.completed@1, return.cancelled@1 |
| Customers | customer.created@1, customer.updated@1, customer.tag_added@1, customer.marketing_consent_changed@1 |
| Carts | checkout.abandoned@1 |
| Products | product.created@1, product.updated@2 (with a non-empty fields list), product.metafield_changed@1 (needs a filter on the custom field definition id), inventory.stock_changed@1 (per variant), review.created@1 |
| The clock | schedule.fired@1 with schedule of hourly, daily, weekly or monthly, in the store time zone |
The facts of each trigger, and the exact variables a text may print, are in the authoring guide (see Get the guide). Do not copy a fact path from memory: a path the trigger does not carry is rejected with a finding.
Origins
trigger.origins says which kinds of write may start a run. Send the same list the dashboard sends:
["USER", "API", "MCP", "ASSISTANT", "BULK", "IMPORT", "DUPLICATE", "SYSTEM", "AUTOMATION"]Leave out RESTORE, MIGRATION and CLONE: copying a whole store is not a change, and would start every automation at once. SYSTEM covers sales, cancellations and restocks done by the platform itself, so an order automation that omits it never sees a storefront order. schedule.fired@1 must list SYSTEM.
Filter
trigger.filter is an optional group { "op": "all" | "any", "rules": [...] } evaluated against the event facts, and against live values (below). A rule is { "path", "op", "value" }. Number operators include eq, neq, gt, gte, lt, lte, plus crossed_below N and crossed_above N where the guide says so (stock and price on product.updated@2 and inventory.stock_changed@1). Text and list operators are listed per path in the guide.
A filter is also a safety device: five actions refuse to exist without one (see Safety model).
Steps
steps is an ordered list, at most 30 in total and 3 levels deep. Step types:
| Step | What it does |
|---|---|
action | Calls one action contract (add_order_tags@1, send_internal_email@1, ...) with an input. |
condition | when a rule group, then a list of steps, optional else. A false condition without an else ends the run as a success (see below). |
wait | Parks the run for 5 minutes to 90 days. Top level only, at most 3 per definition. |
map | Looks a value up in a table you write into the definition (at most 2,000 rows), for product custom fields. |
fetch | Clock automations only. Reads a bounded list of orders, customers or products and publishes steps.<id>.ids, .count, .truncated (and .numbers for orders). |
for_each | Clock automations only, one per definition. Runs up to 5 actions once per fetched id (at most 200 items), each addressing the item as { "$ref": "loop.item" }. |
Values in an action input are either literals or references: { "$ref": "event.entityId" }, { "$ref": "event.facts.customer.id" }, { "$ref": "steps.f1.ids" }. Which reference an action accepts for its target is fixed per action and trigger family; the validator names the exact path when you get it wrong.
Actions
Actions are versioned contracts (name@1). The families:
- Orders:
add_order_tags@1,remove_order_tags@1,mark_order_paid@1,cancel_order@1,set_order_hold@1,archive_order@1,set_order_field@1, and the bulkbulk_add_order_tags@1/bulk_remove_order_tags@1(clock only). - Customers:
add_customer_tags@1,remove_customer_tags@1,send_customer_email@1(a campaign-library template,kindmarketingororder),create_customer_coupon@1,adjust_loyalty_points@1. - Products and stock:
set_product_status@1,add_product_tags@1,remove_product_tags@1,add_product_to_category@1,remove_product_from_category@1,set_product_price@1,set_product_weight@1,set_product_metafield@1,adjust_stock@1,create_purchase_order@1(a draft only). - Discounts:
set_coupon_active@1,set_discount_rule_active@1. - Messages and integrations:
notify_me@1(a notice to the store's managers; a text that printsorder.*,return.*,refund.*,cart.*or a fetched list reaches only managers with VIEW_ORDERS, one that printscustomer.*only those with VIEW_CUSTOMERS, never a channel-restricted member, and approving it needs the same permission),send_internal_email@1(to your own team members, never a customer; on the clock it can carry a report table),send_http_request@1(through a saved HTTP connection).
Which actions run under which trigger is enforced by the validator (an order action under a product trigger is refused with ACTION_TRIGGER_UNSUPPORTED when you validate, not at run time). The per-action inputs, bounds and skip codes are in the guide topics product, inventory, order-actions, actions, messages and http-and-reports.
Facts versus live values
Two kinds of data reach a rule.
Facts are frozen when the event is recorded: event.facts.order.total, event.facts.customer.isFirstOrder, event.facts.stock. They describe the moment of the change. After a wait they are still the old values.
Live values start with current. and are read from the database when the step runs: current.order.financialStatus, current.cart.status, current.return.status, current.customer.totalSpent, current.product.stock. Use them whenever a rule must see today's state, most often in a condition after a wait. Live values:
- work in
conditionsteps and in the trigger filter, never in a$refand never in a text; - are never stored in a run or a history row, never printed in a notice or email, never sent in an HTTP body, so a postcode or an email domain can decide a branch but cannot be read back;
- read as empty when the column has no value, and every rule on an empty value is false;
- exist for the entities the trigger carries (an order trigger gets
current.order.*andcurrent.customer.*, a cart trigger getscurrent.cart.*, a return trigger getscurrent.return.*, and so on). The guide topiclive-valueslists every column.
No name, email, phone number or address is ever in a fact. Texts may print only the variables of their own trigger family ({{order.number}}, {{product.name}}, {{steps.f1.count}}, plus {{store.name}}, {{now.date}}, {{now.time}} everywhere).
Runs and history
Each event that matches an active automation creates one run. A run steps through the definition on a queue, with a lease so a crashed worker cannot lose or double it. The dashboard shows a run's steps (id, status, error code, timings). Run history carries codes and counts only, never values: no event facts, no step inputs or outputs, no names or emails. In the SDK and MCP, getAutomationRun / get_automation_run return the same.
How a run ends
| Status | Meaning |
|---|---|
QUEUED, RUNNING | In flight. |
WAITING | Parked by a wait step, by the backoff after a transient error, or by a rate hold. |
SUCCEEDED | Every step finished. A condition that was false and had no else also ends as SUCCEEDED with the outcome CONDITION_NOT_MET: the rule worked, there was nothing to do. |
SKIPPED | A business skip: the run correctly decided not to act, and wrote nothing. The run carries the reason as a code. |
FAILED | A permanent error (for example PERMISSION_REVOKED, TAG_NOT_FOUND, HTTP_RESPONSE_NOT_OK), or RETRIES_EXHAUSTED after 5 transient retries. Fix the cause, then retry the run from the dashboard. |
NEEDS_REVIEW | The engine cannot tell whether the last step acted (an unknown outcome), the run lost its lease more than 5 times, or it sat queued or waiting for more than 7 days. Check the entity before retrying. |
CANCELLED | Cancelled by pausing the automation with the cancel option. |
Common business skip codes, by action:
- Entity gone or ineligible:
ORDER_NOT_FOUND,CART_NOT_FOUND,PRODUCT_NOT_FOUND,CUSTOMER_NOT_FOUND(a guest order has no customer),SUBJECT_ERASED(a privacy erasure),SUPERSEDED(a newer event or a later change made this one stale). - Orders:
ORDER_NOT_WRITABLE(for examplecancel_order@1never cancels a paid order, because it refunds nothing),ORDER_NOT_HOLDABLE,ORDER_NOT_ARCHIVABLE,ORDER_FIELD_NOT_FOUND,ORDER_FIELD_REFUSED. - Customer email:
NO_CUSTOMER_EMAIL,NO_MARKETING_CONSENT,SUPPRESSED,FREQUENCY_CAP,TEMPLATE_NOT_FOUND,EMAILS_DISABLED,NO_POSTAL_ADDRESS,MARKETING_ON_HOLD,PROMOTIONAL_CONTENT,ORDER_FIELD_EMPTY,RECOVERY_EMAIL_ACTIVE(the store's own abandoned-checkout recovery emails are on, so a second reminder would be sent). - Stock and purchasing:
STOCK_NOT_TRACKED,STOCK_PER_WAREHOUSE,STOCK_NOT_WRITABLE,PO_NO_SUPPLIER,PO_SUPPLIER_NOT_FOUND,PO_ALREADY_OPEN,PO_ITEM_NOT_ORDERABLE. - Other:
LOYALTY_NOT_ACTIVE,LOYALTY_NOT_MEMBER,COUPON_NOT_FOUND,COUPON_EXPIRED,DISCOUNT_RULE_NOT_FOUND,HTTP_CONNECTION_NOT_FOUND,HTTP_CONNECTION_DISABLED,NO_RECIPIENTS,NOTHING_TO_REPORT. - Plan:
PLAN_NOT_INCLUDED(the store dropped below PRO) andPLAN_QUOTA_REACHED(this billing cycle's actions are used up). Both end the whole run before any step.
A skip that means the automation itself is misconfigured (a deleted template, switched-off emails, a paused HTTP connection, a missing supplier) is reported to the store's people once a day. A per-record skip (no consent, no address) never is: it would be noise.
Inside a for_each, an item that no longer matches or cannot be reached is skipped and the loop continues with the next one. A missing template or switched-off emails stops the loop at the first item and the run ends SKIPPED. Items already done stay done. A run with a loop cannot be retried, because people already reached would be reached again; the next scheduled run starts from a fresh list.
Limits and plans
| Plan | Active automations | Actions per billing month |
|---|---|---|
| FREE | 0 | 0 |
| PRO | 10 | 5,000 |
| GROWTH | 25 | 50,000 |
| ENTERPRISE | by agreement | by agreement |
The action cap is a soft cap read when a run starts: a run already going may finish past it. A store that drops below PRO keeps its automations and drafts, but its runs end SKIPPED with PLAN_NOT_INCLUDED.
Engine bounds that apply to every plan (AUTOMATION_LIMITS in @brainerce/types):
| Limit | Value |
|---|---|
| Automations per store, not archived | 50 |
| Active automations per trigger type | 10 |
| Versions per automation | 100 |
| Drafts from API keys, MCP and the assistant | 50 per store per rolling 24 hours (QUOTA_EXCEEDED) |
| Steps per definition, nesting depth | 30, 3 |
| Definition size | 262,144 bytes |
| Name length | 200 characters |
wait steps, one wait | 3 per definition, 5 minutes to 90 days |
fetch steps, items per fetch | 2 per definition, 1 to 200 |
| Orders in a fetch that feeds a bulk tag | 50 |
for_each | 1 per definition, 5 actions, 200 items |
| Actions per hour | 2,000 per automation, 10,000 per store |
| Chain of automations | stops at 3 links |
Over the hourly rate the run waits (WAITING) until the window ends instead of failing.
Safety model
- Approving is a human act. Creating a version never runs anything. A signed-in dashboard user reviews the exact definition, approves it and turns it on. An API key gets
403 APPROVAL_REQUIRES_DASHBOARD_USERon approve and403 ACTIVATION_REQUIRES_DASHBOARD_USERon activate and switch-version, whatever its scopes. There is no override and no scope for it. An AI tool gets the same unless the merchant granted it the separateautomations:activatescope (on top ofautomations:readandautomations:write) on a signed-in connection, and then onlyactivate_automationworks, only for low-risk actions (tags, and notices or emails to the store's own team): see Turning one on from an AI client. Resume, switch-version and un-archive stay dashboard-only for everyone. - The approver is the identity the runs act as. At approval the permissions the actions need are bound to that person. If they later lose a permission, the run fails with
PERMISSION_REVOKEDand the automation is paused automatically. A person limited to some sales channels cannot approve. - Versions are immutable and approval binds to a hash. An edit is a new version. The active version keeps running until a person approves the new one and switches to it. Approval is tied to the
definitionHashthe approver saw (409 DEFINITION_HASH_MISMATCHif it changed under them). - Guarded actions need a filter.
cancel_order@1,set_order_hold@1,archive_order@1,adjust_stock@1andcreate_purchase_order@1must sit under a trigger filter with at least one rule, or under aconditionstep. Otherwise the definition is refused withACTION_NEEDS_GUARD, because they would run on every event of the trigger. - No automation loops. An automation never runs on its own change. A change made by an automation carries the origin
AUTOMATIONand a chain depth, and the relay blocks events at chain depth 3. - No personal data in facts or history. Facts hold ids, counts, enums and totals, never a name, email, phone or address. Live values are conditions only. Texts cannot print a field the trigger family does not offer.
- Customer email respects consent.
send_customer_email@1withkind: "marketing"needs the customer's marketing consent at the moment it sends, carries the unsubscribe link, honours the suppression list and a per-customer frequency cap (frequencyDays, 1 to 90: the cap reads run history, which is kept 90 days). An email about an order that reads like an offer is skipped (PROMOTIONAL_CONTENT). - HTTP connections are created in the dashboard only.
send_http_request@1names a saved connection by id, never a URL or a secret. The connection holds the address, header values and a signing secret; the definition adds only a relative path and a body. - Money does not move. No action refunds.
cancel_order@1skips a paid order.mark_order_paid@1books a manual payment like the dashboard button and collects nothing.
Four ways to build one
- The dashboard editor. Settings, then Automations. Pick a trigger (When), optionally narrow it (Filter), then add steps (Then). Test on an order (or customer, cart, product, Test now for the clock) shows what the automation would do on a real record and writes and sends nothing. Save, then Approve and turn on.
- The admin MCP server. Twelve tools under the
automations:readandautomations:writescopes. Drafts only. See Automations on the Admin MCP. - The REST API and the SDK. An API key with the automations scopes, routes under
/api/stores/{storeId}/automations. See Automations REST API and Automations in the SDK. - BOBO, the in-dashboard assistant. It drafts from a plain-language request, tests, and hands the draft to the merchant. Drafts only: it cannot approve or turn on.
All four create the same objects and run the same validator. Ways 2 to 4 count against the 50 drafts per 24 hours.
The flow for an integration or an AI agent
- Get the guide. Once, before writing a definition.
- Validate. Fix every finding (
codeandpath) untilokis true. - Test on a real record. Order, customer, product or cart of the store. It writes nothing.
- Save a draft. A new automation, or a new version of an existing one.
- The merchant approves in the dashboard. Tell them so; never say the automation is live, unless
activate_automationjust succeeded (only for tag and team-notice automations, only with theautomations:activatescope).
Get the guide
get_automation_guide (MCP) and GET /api/stores/{storeId}/automations/guide (REST, scope automations:read) return the same text, the single source of truth for what a definition may contain. With no topic you get an index and the basics. Ask for the topic you need, or all (about 40 KB) when a definition spans several families.
| Topic id | Covers |
|---|---|
basics | The shape of a definition, origins, steps, map, set_product_metafield@1. |
product | product.updated@2 and the product actions. |
reviews | review.created@1. |
inventory | inventory.stock_changed@1, adjust_stock@1, create_purchase_order@1. |
order-actions | adjust_loyalty_points@1, set_order_hold@1, archive_order@1, set_order_field@1. |
live-values | Every current.* column. |
triggers | Order, return, refund, customer and cart triggers and their facts. |
clock | schedule.fired@1, fetch, bulk tag actions, for_each. |
facts | Order and customer facts, the variables a text may use per trigger. |
actions | wait, order and customer tags, mark_order_paid@1, cancel_order@1, coupons on or off. |
messages | Team and customer email, order fields in a text, discount rules. |
http-and-reports | send_http_request@1, weight, personal coupons, report tables, every text variable. |
Worked examples
Each recipe is a complete definition that passes the validator, with the exact tool calls to create it:
Region-Restricted Coupons
Limit a coupon to specific regions. An empty region list applies everywhere, and a non-empty list redeems only for buyers whose checkout region is in it.
Storefront SDK Reference (brainerce)
Every reachable method on BrainerceClient, the storefront SDK. Grouped by domain, with the auth mode each one needs, ordered by the mandatory storefront flow.