Skip to main content

Workflows

A workflow is an automation graph: a trigger event, then a set of nodes connected by edges. It is what the visual builder in the LeadX app produces, and the execution engine lives in leadx-ms-workflow.

You never call the workflow service directly — it is internal and requires its own token. Everything goes through leadx-api.

Create

curl -X POST https://api.leadx.in/api/key/protected/workflow \
-H "apikey: $KEY" -H "Content-Type: application/json" \
-d '{
"name": "Welcome new website leads",
"triggerEventType": "lead.created",
"config": {},
"nodes": [
{ "id": "n1", "type": "trigger", "data": { "eventType": "lead.created" } },
{ "id": "n2", "type": "condition", "data": { "field": "source", "op": "equals", "value": "Website" } },
{ "id": "n3", "type": "action", "data": { "action": "send", "mode": "smtp", "template": "665c..." } }
],
"edges": [
{ "source": "n1", "target": "n2" },
{ "source": "n2", "target": "n3", "sourceHandle": "true" }
]
}'
FieldNotes
nameMade unique automatically — a clashing name gets a suffix rather than an error.
triggerEventTypeThe event that starts a run.
nodes / edgesThe graph. Sent whole; PUT replaces the graph rather than patching it.
configWorkflow-level settings.
scheduleFor time-triggered workflows instead of event-triggered.

Trigger events

EventFires when
lead.createdA lead is created, by any path.
lead.updatedA lead changes.
contact.createdA contact is created.
contact.updatedA contact changes.
email.sentAn email goes out.
whatsapp.sentA WhatsApp message goes out.
whatsapp.receivedAn inbound WhatsApp message arrives.
whatsapp.template.approvedMeta approves a template.
call.completedA call log is closed.

:::note Campaigns can suppress events Campaign creation takes triggerWorkflow (default true). Setting it false stops a bulk send from firing email.sent/whatsapp.sent for every recipient — worth doing when a large campaign would otherwise trigger thousands of workflow runs. :::

Publish

A workflow does not run until it is published.

MethodEndpoint
POST/workflow/:id/publish
POST/workflow/:id/unpublish

Unpublishing stops new runs; it does not cancel runs already in flight.

Manage definitions

MethodEndpointPurpose
GET/workflowList.
POST/workflowCreate.
DELETE/workflowBulk delete — { "ids": [...] }.
GET/workflow/:idRead, with graph hydrated.
PUT/workflow/:idUpdate. Replaces the graph.
DELETE/workflow/:idDelete one.

Runs

Each trigger creates a run with its own state.

MethodEndpointPurpose
GET/workflow/runsList runs. Filter by workflow and status.
DELETE/workflow/runsBulk delete runs.
DELETE/workflow/runs/:runIdDelete one run.
POST/workflow/runs/:runId/pausePause.
POST/workflow/runs/:runId/resumeResume.
POST/workflow/runs/:runId/cancelCancel — terminal.
POST/workflow/runs/:runId/restartRe-run from the start.
POST/workflow/:id/runs/pausePause every in-flight run of one workflow.

POST /workflow/:id/runs/pause is the emergency brake: use it when a published workflow is misbehaving and you want to stop the bleeding before editing it.

A safe change process

  1. POST /workflow/:id/runs/pause — freeze in-flight runs.
  2. POST /workflow/:id/unpublish — stop new ones.
  3. PUT /workflow/:id — send the full new graph.
  4. POST /workflow/:id/publish.
  5. GET /workflow/runs?filters={"workflow":"..."} — confirm new runs look right.

Action nodes and sending

Send actions inside a workflow route through leadx-ms-unified-chat, the same path as one-to-one replies and Genie outreach — not through the campaign sender. Their messages land in the unified inbox like any other.