Win back lapsed customers
A weekly automation that finds customers who have not ordered for 90 days and tags and emails each one in a loop. A validated definition using fetch and for_each on the clock.
Every Monday, find customers who agreed to marketing and have not ordered in 90 days, tag each one and send them a library email. Trigger: schedule.fired@1. Steps: fetch (customers), for_each with add_customer_tags@1 and send_customer_email@1.
Model background: Automations.
The definition
{
"schemaVersion": 1,
"trigger": {
"type": "schedule.fired@1",
"origins": ["SYSTEM"],
"schedule": {
"frequency": "weekly",
"weekday": 1,
"time": "10:00"
}
},
"steps": [
{
"id": "f1",
"type": "fetch",
"source": "customers",
"where": {
"lastOrderOlderThanDays": 90,
"acceptsMarketing": true
},
"limit": 50
},
{
"id": "l1",
"type": "for_each",
"items": {
"$ref": "steps.f1.ids"
},
"do": [
{
"id": "tag",
"type": "action",
"contract": "add_customer_tags@1",
"input": {
"customerId": {
"$ref": "loop.item"
},
"tagIds": ["TAG_ID_WIN_BACK"]
}
},
{
"id": "mail",
"type": "action",
"contract": "send_customer_email@1",
"input": {
"customerId": {
"$ref": "loop.item"
},
"templateId": "TEMPLATE_ID",
"kind": "marketing",
"frequencyDays": 60
}
}
]
}
]
}Replace before saving:
TAG_ID_WIN_BACK: the id of an existing customer tag.TEMPLATE_ID: a template in the store's campaign library.lastOrderOlderThanDays(1 to 365),limit(1 to 200) and the schedule (weekday0 is Sunday,timeis in the store's time zone).
How it works
- A customers
fetchtakeswhereoflastOrderOlderThanDays(a customer with no order never matches),signedUpOlderThanDays,tagIds(1 to 12) andacceptsMarketing, and needs at least one. It publishessteps.f1.ids,.countand.truncatedbut no.numbers. It returns ids, never a name, email or phone, and leaves out erased customers. for_eachruns itsdolist once per fetched id: at most 5 actions, at most 200 items, one loop per definition, clock only. Inside it the customer is always{ "$ref": "loop.item" }. For customers the allowed loop actions areadd_customer_tags@1,remove_customer_tags@1,send_customer_email@1(kindmarketing) andcreate_customer_coupon@1. A wait, a fetch, a condition, another loop, a notice, a team email, an HTTP call,cancel_order@1andmark_order_paid@1are never allowed inside.acceptsMarketing: truenarrows the list, but consent is checked again at the moment each email is sent.
How the loop ends
- An item that no longer matches the fetch when its turn comes is skipped.
- A customer without marketing consent, with no address, suppressed, or over the frequency cap is skipped and the loop goes on with the next one.
- A missing template or switched-off emails stops the loop at the first item and the run ends
SKIPPED. - A permanent failure fails the run. The items already done stay done.
- A loop run cannot be retried. Retrying would reach the same people again. The next scheduled run starts from a fresh list.
What it does not do
- It will pick the same customers next Monday, because they still have not ordered.
frequencyDays: 60is what stops a second email: those customers are skipped withFREQUENCY_CAPuntil 60 days have passed. The tag is added again harmlessly. - It reaches at most
limitcustomers per run (200 at most). Whensteps.f1.truncatedis true, the rest wait for a later run. - It does not put a discount code in the email. A personal code is
create_customer_coupon@1in the loop (percent or fixed,expiresInDays1 to 365), and a marketing email may print{{coupon.code}}: add that step before the email, and read the guide topichttp-and-reports. - It does not email without the store's postal address (
NO_POSTAL_ADDRESS).
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 and shows ONE looping step: how many customers it would reach, per action how many would change or be skipped and why, where the run would stop, and at most 10 ids. It writes and sends nothing.create_automation_draftwithname: "Win back lapsed customers".- Tell the merchant to approve it in the dashboard.
With the SDK:
const check = await admin.validateAutomationDefinition(storeId, { definition });
if (!check.ok) throw new Error(JSON.stringify(check.errors));
const draft = await admin.createAutomation(storeId, {
name: 'Win back lapsed customers',
definition,
});What the merchant sees
A draft in Settings, then Automations. Once on, one run a week. Its detail groups the per-item results by action, status and code (with a sample of at most 20 skipped or failed items), for example (illustrative numbers) "send_customer_email: 31 sent, 12 skipped FREQUENCY_CAP, 3 skipped NO_MARKETING_CONSENT". It never lists names or addresses.
Hold risky first orders for review
An automation that puts a new customer's large first order on hold, tags it and notifies the managers, so nothing ships until a person releases it. A validated definition using a guarded action.
Alert the warehouse when a paid order is edited
An automation that tags a paid order and emails the warehouse when its items or shipping address change after payment. A validated definition using order.edited@1 and a live financial-status check.