Low-stock alert for the team
An automation that emails your team once when a variant's sellable stock drops below your own number, with a complete validated definition and the exact MCP and SDK calls to draft it.
Email the people who reorder stock the moment a variant runs low, once, not on every sale after that. Trigger: inventory.stock_changed@1. Action: send_internal_email@1.
For the model behind this page (events, filters, runs, plans) read Automations.
The definition
{
"schemaVersion": 1,
"trigger": {
"type": "inventory.stock_changed@1",
"origins": [
"USER",
"API",
"MCP",
"ASSISTANT",
"BULK",
"IMPORT",
"DUPLICATE",
"SYSTEM",
"AUTOMATION"
]
},
"steps": [
{
"id": "low",
"type": "condition",
"when": {
"op": "all",
"rules": [
{
"path": "event.facts.stock",
"op": "crossed_below",
"value": 5
}
]
},
"then": [
{
"id": "alert",
"type": "action",
"contract": "send_internal_email@1",
"input": {
"recipientUserIds": ["user_REPLACE_WITH_TEAM_MEMBER_ID"],
"subject": "Low stock: {{product.name}}",
"body": "{{product.name}} {{variant.name}} (SKU {{product.sku}}) went from {{stock.before}} to {{stock.after}} units.",
"includeEntityLink": false
}
}
]
}
]
}Replace before saving:
recipientUserIds: the user ids of 1 to 5 store team members (never an email address). Each must still be allowed to receive the email, or the run endsSKIPPEDwithNO_RECIPIENTS. The Admin MCP team tools list the members and their ids.- The number
5: your own threshold. The store's low-stock setting is not in the event, so the number lives in the rule.
How it works
inventory.stock_changed@1fires once per variant whenever its sellable stock really changes: a sale, a restock, a manual adjustment, a transfer, a cancellation. A cart hold does not move it. A product with no variants counts as one variant. Untracked stock and kits never fire it.crossed_below 5is true when the stock was 5 or more and is now below 5. It tells you once when stock passes 5, not on every sale below it.lte 5would email on every sale under 5. Usecrossed_below 1for "sold out" andcrossed_above 0for "back in stock".- The rule reads
event.facts.stock, neverevent.facts.product.stock. - The text may use
{{product.name}},{{product.sku}},{{variant.name}},{{variant.sku}},{{stock.before}}and{{stock.after}}.{{product.stock}}is not available under this trigger and the validator rejects it (NOTIFY_VARIABLE_UNKNOWN). includeEntityLinkisfalse: a stock email carries no link to the product.
Want a notice in the dashboard instead of an email? Swap the action for notify_me@1 with an input of { "title": "Low stock", "message": "{{product.name}} {{variant.name}} is down to {{stock.after}}" }.
What it does not do
- It does not reorder. To draft a purchase order from the same event add
create_purchase_order@1(a guarded action: it needs the condition above). Nothing is sent to a supplier and no stock moves until a person sends and receives the order. - It is per variant. A product with three sizes can email three times.
- Two automations that each write the other's trigger can chain up to 3 times. Keep one automation per item.
Create it
With the Admin MCP (scopes automations:read and automations:write):
get_automation_guidewithtopic: "inventory".validate_automation_definitionwith the definition. Fix every finding.test_automationwithentity: { "type": "Product", "id": "<a product id>" }. It shows the rendered email and how many people it would reach, and sends nothing. (Over REST and in the SDK, a product with variants also needsvariantId: see Test an automation.)create_automation_draftwithname: "Low stock alert"and the definition.- Tell the merchant to approve it in the dashboard.
With the SDK (apiKey mode, server only):
import { BrainerceClient } from 'brainerce';
const admin = new BrainerceClient({ apiKey: process.env.BRAINERCE_API_KEY! });
const check = await admin.validateAutomationDefinition(storeId, { definition });
if (!check.ok) throw new Error(JSON.stringify(check.errors));
const trial = await admin.testAutomation(storeId, {
definition,
entity: { type: 'Product', id: productId },
variantId, // required when the product has variants
});
const draft = await admin.createAutomation(storeId, { name: 'Low stock alert', definition });
// draft.versionId is a DRAFT. Nothing runs until a person approves it.What the merchant sees
The draft appears under Settings, then Automations, with the status Draft. They open it, read the definition, and choose Approve and turn on. From then on the list shows how many runs of the last 7 days updated, skipped or failed. Your team gets an email such as "Low stock: Blue Tee". A run that finds none of the chosen people still allowed to receive it ends SKIPPED with NO_RECIPIENTS.
Custom checkout flow
Drive the Brainerce checkout step by step from your own UI. The real endpoints, the 30-minute expiry, the payment gate, and what the platform will not let you build.
Tag VIP customers on a first big order
An automation that tags the order and its customer when a new customer's first paid order passes an amount, with a validated definition and the MCP and SDK calls to draft it.