Sweep unpaid orders every morning
A scheduled automation that finds orders still unpaid after 3 days, tags them and sends the order numbers as a notice. A validated definition using the clock trigger, a fetch step and a bulk tag action.
Every morning, list the orders still unpaid after 3 days, tag them, and tell the store's managers which ones. This is the usual chase list for bank transfers and other manual payments. Trigger: schedule.fired@1. Steps: fetch, bulk_add_order_tags@1, notify_me@1.
Model background: Automations.
The definition
{
"schemaVersion": 1,
"trigger": {
"type": "schedule.fired@1",
"origins": ["SYSTEM"],
"schedule": {
"frequency": "daily",
"time": "09:00"
}
},
"steps": [
{
"id": "f1",
"type": "fetch",
"source": "orders",
"where": {
"financialStatus": ["pending"],
"olderThanDays": 3
},
"limit": 50
},
{
"id": "tagall",
"type": "action",
"contract": "bulk_add_order_tags@1",
"input": {
"orderIds": {
"$ref": "steps.f1.ids"
},
"tags": ["unpaid-3d"]
}
},
{
"id": "note",
"type": "action",
"contract": "notify_me@1",
"input": {
"title": "{{steps.f1.count}} unpaid orders older than 3 days",
"message": "Orders: {{steps.f1.numbers}}"
}
}
]
}Replace before saving: time (in the store's time zone), the olderThanDays value (1 to 365), and the tag.
How it works
schedule.fired@1runs by the clock, with no data.originsmust includeSYSTEM.scheduleis one of{ "frequency": "hourly", "minute": 0 },{ "frequency": "daily", "time": "09:00" },{ "frequency": "weekly", "weekday": 1, "time": "09:00" }(0 is Sunday) or{ "frequency": "monthly", "dayOfMonth": 1, "time": "09:00" }(1 to 28). A missed occurrence fires once when the platform is back, never retroactively.- Under the clock there are no facts to filter on. You choose records with a top-level
fetchstep.whereneeds at least one filter. Here:financialStatus: ["pending"]andolderThanDays: 3. A fetch publishessteps.f1.ids,.numbers(order numbers),.countand.truncated. It never returns an order row, name, email or total. Cancelled orders are left out unlesswhere.statusnamesCANCELLED. bulk_add_order_tags@1takesorderIdsof exactly{ "$ref": "steps.f1.ids" }, never a typed list, and tags every fetched order in one change. The fetch that feeds a bulk action has alimitof at most 50.notify_me@1may print{{steps.f1.count}}and{{steps.f1.numbers}}.
What it does not do
- The fetch cannot filter on payment method, so it covers every unpaid order, not only bank transfers. In practice most of what stays pending for 3 days is a manual payment.
- It takes the oldest 50. A tagged order is still unpaid tomorrow, so with more than 50 orders waiting, the same oldest 50 come back every day until they are paid or cancelled, and
steps.f1.truncatedis true. Clear the backlog first, or run it with a smallerolderThanDaysonce it is under control. - It never cancels. Cancelling would need
cancel_order@1, which skips an order that is paid or has a payment waiting. - For a table in an email instead of a notice,
send_internal_email@1under the clock accepts aninput.reportand sends nothing when the table is empty (NOTHING_TO_REPORT).
Create it
With the Admin MCP:
get_automation_guidewithtopic: "clock".validate_automation_definition. Fix every finding.test_automationwithentity: { "type": "Store", "id": "<the store id>" }. It reads the list right now, shows which orders it would tag and how the notice would read, and writes nothing.create_automation_draftwithname: "Unpaid orders sweep".- Tell the merchant to approve it in the dashboard.
With the SDK:
// The clock is tested on the Store; entity.id is the store id.
const result = await admin.testAutomation(storeId, {
definition,
entity: { type: 'Store', id: storeId },
});
const draft = await admin.createAutomation(storeId, { name: 'Unpaid orders sweep', definition });What the merchant sees
A notice each morning such as "4 unpaid orders older than 3 days" with the order numbers, and the tag unpaid-3d on those orders so they can filter the orders list. The history shows one run per day.
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.
Abandoned cart reminder with a live check
An automation that waits after a cart goes idle, re-checks that it is still abandoned, then sends a library email to the shopper. A validated definition using a wait step and a live current.cart value.