Automations REST API

The routes for reading, validating, testing and drafting automations with an API key, what an API key can never do (approve, activate), the error codes, and the scopes. Not part of the generated endpoint reference.

This page is written by hand because the automation routes are not in the generated endpoint reference: they are store-scoped routes under /api/stores/{storeId}/automations, not /v1 routes. For what an automation is, the model and the limits, read Automations. For ready definitions, see the automation recipes.

https://api.brainerce.com/api/stores/{storeId}/automations

Authenticate with Authorization: Bearer brainerce_... (an API key) or, from the dashboard, a signed-in session. See Authentication. Every route that writes, validates, tests, activates or retries needs a store on a plan that includes automations. On FREE the guard answers with PLAN_FEATURE_REQUIRED (feature automations, required plan PRO) before the route runs. The stop routes (pause, pause-and-cancel, archive) and the read routes (list, get, version, runs, run, guide) are exempt: a store that dropped to a lower plan keeps its active automations in place (inert), so it can still stop them and read their history.

Scopes

ScopeStore permissionRoutes
automations:readView automationsEvery GET below, including the guide.
automations:writeManage automationsValidate, test, create, new version, rename, duplicate, pause, pause-and-cancel, archive, retry a run.

A run's labels (a product name, an order number, a customer name) are filled in only when the key also holds the matching read scope (products:read, orders:read, customers:read). Without them the run carries codes and counts only. Testing an automation needs the read scope of the thing you test on (see Test).

Reads

Method and pathWhat it returns
GET /automationsAutomations, most recently updated first, with the latest version and the last 7 days of runs counted by status. Query: page, limit (default 20, at most 100), status (DRAFT, ACTIVE, PAUSED, ARCHIVED), search.
GET /automations/guideThe authoring guide as text. Query topic: omit for the index plus the basics, a topic id, or all (about 40 KB). The same text as the MCP tool get_automation_guide.
GET /automations/{automationId}One automation and its versions (newest first, at most 100), without definitions.
GET /automations/{automationId}/versions/{versionId}One version with its full definition, its definitionHash, the approval fields, the grant (stored once approved, otherwise a preview), and whether it differs from the active version.
GET /automations/{automationId}/runsRuns, newest first, with the triggering event and the outcome or error codes. Query: page, limit, status (a run status).
GET /automations/{automationId}/runs/{runId}One run with its steps (id, status, error code, timings; at most 200). A for_each loop's per-item rows are grouped under loopChildren by status and code, with a sample of at most 20 skipped or failed items.

Run history never contains a value: no event facts, no step input or output.

Drafts and tests

All of these need automations:write and a store permission to manage automations.

Method and pathWhat it does
POST /automations/validateChecks a definition and writes nothing. Body { "definition": {...} }. Returns ok, errors ({ code, path }), the hash a save would compute, the referenced custom field definitions as resolved, and the grant an approval would bind. Advisory: save and approve check again.
POST /automations/testDry run on one real record. See below.
POST /automationsCreates a DRAFT automation and its version 1. Body { "name", "definition" }. Returns automationId, versionId, version, definitionHash.
POST /automations/{automationId}/versionsSaves an edit as a new immutable draft version. Body { "definition" }. The trigger type cannot change (409 TRIGGER_TYPE_CHANGE).
PATCH /automations/{automationId}Renames only. No new version, no re-approval.
POST /automations/{automationId}/duplicateCopies an automation as a new draft.
POST /automations/{automationId}/pauseStops new runs. Runs already queued or started continue.
POST /automations/{automationId}/pause-and-cancelPauses and also cancels the runs still queued or waiting.
POST /automations/{automationId}/archiveArchives it. Terminal.
POST /automations/{automationId}/runs/{runId}/retryRuns one finished FAILED or NEEDS_REVIEW run again with the same trigger event, on the current active version. Not available for a loop run, and not available when an earlier attempt already succeeded at send_customer_email@1 or send_http_request@1 (it would reach the person or system twice). An earlier success at adjust_loyalty_points@1, adjust_stock@1, create_purchase_order@1 or create_customer_coupon@1 is not repeated: the new attempt records that step as done and continues with the next one, as long as the step (and any condition it sits inside) is unchanged in the version the retry runs on. A refusal is 409 RUN_AGAIN_AFTER_ACCUMULATING_STEP with reason: STEP_CHANGED (a carried step or its condition was edited, moved or removed), RECORD_MISSING (the stored record of a carried step is gone) or SEND_MAY_HAVE_GONE_OUT (an email or HTTP request step queued its job, even if the run then failed).

Test an automation

POST /automations/test takes the definition (saved or not) plus exactly one of:

  • productId, or entity: { "type": "Product", "id" }, optionally with a simulated change of { field, before, after } (for product.updated triggers) and, for inventory.stock_changed@1, a variantId (required when the product has variants), or
  • entity: { "type", "id" } where type is Order, Customer, Cart or Store (the clock; the id is the store id), plus an optional automationId so a customer email step checks its frequency cap against the real history. change is refused here.

Use an Order for order, refund, return, order.edited@1 and order.field_set@1 triggers, a Customer for customer triggers, a Cart for checkout.abandoned@1, a Product for product, inventory and review triggers (a review test is built from the product's most recent real review, 404 REVIEW_NOT_FOUND when it has none), and the Store for schedule.fired@1. product.created@1 and product.metafield_changed@1 cannot be tested (400 TEST_TRIGGER_UNSUPPORTED). Sending neither productId nor entity, or both, is 400 TEST_ENTITY_INVALID.

The answer says whether the trigger matches, how each condition resolves, and for each action the change it would make or the reason it would skip, ending with wroteNothing: true. A wait is shown as would_wait and never waited. A condition on a current.* value is judged on today's data and marked evaluatedOnCurrentValues. A for_each loop is shown as one would_loop step with counts per action and at most 10 ids. It writes nothing, sends nothing and records nothing.

curl -sS -X POST "https://api.brainerce.com/api/stores/$STORE_ID/automations/test" \
  -H "Authorization: Bearer $BRAINERCE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "definition": { ... }, "entity": { "type": "Order", "id": "ord_..." } }'

Access rules: testing on a product needs the right to view every product, on an order every order and customers (the result shows the customer), on a customer every customer, on a cart every order. An API key needs the matching read scope. Otherwise 403 TEST_REQUIRES_PRODUCT_ACCESS, TEST_REQUIRES_ORDER_ACCESS, TEST_REQUIRES_CUSTOMER_ACCESS or TEST_REQUIRES_CART_ACCESS.

What an API key can never do

RouteAnswer for an API key
POST /automations/{automationId}/approve403 APPROVAL_REQUIRES_DASHBOARD_USER
POST /automations/{automationId}/activate403 ACTIVATION_REQUIRES_DASHBOARD_USER
POST /automations/{automationId}/switch-version403 ACTIVATION_REQUIRES_DASHBOARD_USER

Approve, activate and switch-version are a signed-in dashboard click, whatever scopes the key holds. The person who approves becomes the identity the runs act as, and the permissions the actions need are bound to them at that moment. HTTP connections (the saved targets of send_http_request@1, with their header values and signing secret) are created in the dashboard only, so a definition can name a connection id but never a URL or a secret.

The flow for an integration is therefore: get the guide, validate, test on a real record, save a draft, and have the merchant approve it in the dashboard.

Errors

StatusCodeMeaning
400DEFINITION_INVALIDThe validator refused the definition. The findings ({ code, path }) are in the error details. Common: ACTION_NEEDS_GUARD, ACTION_TRIGGER_UNSUPPORTED, CUSTOMER_ID_INVALID, NOTIFY_VARIABLE_UNKNOWN, PREFILTER_REQUIRED.
400NAME_INVALID, NAME_TOO_LONG, DEFINITION_TOO_LARGEName rules (at most 200 characters) and the 262,144 byte definition cap.
400TEST_ENTITY_INVALID, TEST_TRIGGER_UNSUPPORTED, TEST_CHANGE_INVALID, TEST_VARIANT_REQUIRED, TEST_STOCK_NOT_TRACKEDThe test body is wrong, the trigger does not take that entity, or a stock test names no variant or an untracked one.
403APPROVAL_REQUIRES_DASHBOARD_USER, ACTIVATION_REQUIRES_DASHBOARD_USERSee above.
403APPROVER_NOT_PERMITTED, ACTIVATOR_NOT_PERMITTEDThe dashboard user lacks a permission the grant needs, or is limited to some sales channels.
404AUTOMATION_NOT_FOUND, VERSION_NOT_FOUND, RUN_NOT_FOUND, PRODUCT_NOT_FOUND, VARIANT_NOT_FOUND, ORDER_NOT_FOUND, CUSTOMER_NOT_FOUND, CART_NOT_FOUND, REVIEW_NOT_FOUND, STORE_NOT_FOUNDThe id is not in this store.
409QUOTA_EXCEEDEDMore than 50 drafts from API keys, MCP and the assistant in a rolling 24 hours, or another quota in Limits and plans.
409TRIGGER_TYPE_CHANGE, AUTOMATION_ARCHIVED, AUTOMATION_ALREADY_ACTIVE, VERSION_NOT_APPROVED, DEFINITION_HASH_MISMATCHLifecycle conflicts.
409RUN_NOT_RETRYABLE, RUN_OUTCOME_UNKNOWN, RUN_TOO_OLD, RUN_RETRY_LIMIT, RUN_AGAIN_NOT_ALLOWED_FOR_LOOP, RUN_AGAIN_AFTER_ACCUMULATING_STEP, AUTOMATION_NOT_ACTIVEA run cannot be run again.
409AUTOMATION_LOCK_CONFLICTRetryable. Try again.

From code

The SDK wraps these routes, including the guide and the test. See Automations in the SDK. The same operations are available to an AI client as 12 tools on the Admin MCP: Automations on the Admin MCP.