Back to Developer

Workflows

Automate your business with event-driven workflows. Define triggers, conditions, and actions that run automatically when events occur.

How It Works

A workflow is a rule that says: when this event happens, if these conditions are met, perform these actions. Workflows run automatically in the background and log every execution for debugging.

  1. 1.Trigger — The event that starts the workflow (e.g. order.created).
  2. 2.Conditions — Optional filters that must be true for the workflow to proceed (e.g. order total > $100).
  3. 3.Actions — One or more actions to execute (e.g. send an email, update inventory).

Create a Workflow

curl -X POST https://vm.whaletools.cloud/v1/stores/{storeId}/workflows \
  -H "x-api-key: wk_live_your_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Low Stock Alert",
    "description": "Send an email when inventory drops below threshold",
    "trigger": {
      "type": "inventory.low",
      "config": { "threshold": 10 }
    },
    "conditions": [
      { "field": "product.status", "operator": "eq", "value": "active" }
    ],
    "actions": [
      {
        "type": "send_email",
        "config": {
          "to": "inventory@yourstore.com",
          "subject": "Low Stock: {{product.name}}",
          "body": "{{product.name}} (SKU: {{product.sku}}) has dropped to {{inventory.quantity}} units at {{location.name}}."
        }
      }
    ],
    "is_active": true
  }'

// Response (201 Created)
{
  "object": "workflow",
  "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "name": "Low Stock Alert",
  "trigger": { "type": "inventory.low" },
  "is_active": true,
  "total_runs": 0,
  "created_at": "2026-03-09T12:00:00.000Z"
}

Trigger Types

TriggerDescription
order.createdFires when a new order is placed.
order.updatedFires when an order status, payment, or fulfillment changes.
order.cancelledFires when an order is cancelled.
inventory.lowFires when stock drops below the configured threshold.
inventory.adjustedFires when stock levels are manually adjusted.
customer.createdFires when a new customer registers.
customer.updatedFires when a customer profile is modified.
product.createdFires when a new product is added to the catalog.
product.updatedFires when product details change.
checkout.completedFires when a checkout is finalized into an order.
schedule.cronFires on a cron schedule (e.g. daily at 9am).

Action Types

ActionDescription
send_emailSend an email using a template or custom body.
update_inventoryAdjust stock levels for a product at a location.
create_taskCreate a task in the store task queue.
webhookSend a POST request to an external URL with the event payload.
send_smsSend an SMS notification to a phone number.
tag_customerAdd or remove tags on a customer profile.
create_order_noteAdd an internal note to an order.

Conditions

Conditions filter which events actually trigger the workflow. Each condition specifies a field, operator, and value. All conditions must be true for the workflow to run.

"conditions": [
  { "field": "order.total", "operator": "gte", "value": 100 },
  { "field": "order.payment_method", "operator": "eq", "value": "card" },
  { "field": "customer.tags", "operator": "contains", "value": "vip" }
]

// Supported operators:
// eq       — equals
// neq      — not equals
// gt       — greater than
// gte      — greater than or equal
// lt       — less than
// lte      — less than or equal
// contains — array/string contains value
// in       — value is in array

Template Variables

Use double curly braces to reference event data in action configurations. Variables are resolved at execution time from the trigger event payload.

// Available variables depend on the trigger type

// order triggers
{{order.id}}
{{order.order_number}}
{{order.total}}
{{order.status}}
{{customer.name}}
{{customer.email}}

// inventory triggers
{{product.name}}
{{product.sku}}
{{inventory.quantity}}
{{location.name}}

// customer triggers
{{customer.id}}
{{customer.name}}
{{customer.email}}
{{customer.phone}}

Workflow Runs

Every workflow execution is logged. View run history to debug failures, check action results, and monitor performance.

// List workflow runs
curl https://vm.whaletools.cloud/v1/stores/{storeId}/workflows/{workflowId}/runs \
  -H "x-api-key: wk_live_your_key_here"

// Response
{
  "object": "list",
  "data": [
    {
      "id": "run_abc123",
      "status": "completed",
      "trigger_event": "inventory.low",
      "actions_executed": 1,
      "started_at": "2026-03-09T12:00:00.000Z",
      "completed_at": "2026-03-09T12:00:01.234Z"
    }
  ],
  "has_more": false
}