Workflows
SDK methods for managing event-driven workflow automations.
The client.workflows namespace provides typed methods for creating, managing, and evaluating event-driven workflow automations. Workflows match incoming events to trigger conditions and execute ordered action sequences. Available in TypeScript, Python, and Go SDKs.
| SDK | Install | Namespace |
|---|---|---|
| TypeScript | npm install @caldera/platformxe-sdk | client.workflows |
| Python | pip install platformxe | client.workflows |
| Go | go get github.com/calderaxe/platformxe-go | client.Workflows |
List workflows
const { workflows } = await client.workflows.list();
for (const wf of workflows) {
console.log(`${wf.id}: ${wf.name} (${wf.isActive ? 'active' : 'inactive'})`);
}
# The first page (50 per page): {"triggers": [...], "pagination": {"page", "limit", "total"}}
result = client.workflows.list()
# Any page, and the route's filters
page = client.workflows.list(page=2, limit=100, is_active=True, trigger_type="EVENT", event_type="PAYMENT_RECEIVED")
for trigger in page["triggers"]:
print(trigger["id"], trigger["code"], trigger["isActive"])
// The first page (50 per page)
result, err := client.Workflows.List()
// Any page, and the route's filters
active := true
page, err := client.Workflows.List(&platformxe.WorkflowListOptions{
Page: 2, Limit: 100, IsActive: &active, TriggerType: "EVENT", EventType: "PAYMENT_RECEIVED",
})
for _, t := range page.Triggers {
fmt.Println(t.ID, t.Code, t.IsActive)
}
// page.Pagination.Total counts every match: page on until Page*Limit >= Total.
In Python and Go, page and limit start at 1 (limit above 100 is 100), is_active / IsActive lists only active or only switched-off triggers, and trigger_type (EVENT or SCHEDULE) and event_type filter by type; an unknown trigger or event type is 400 VALIDATION_ERROR.
Create a workflow
Define a workflow with a trigger configuration and an ordered list of actions.
const workflow = await client.workflows.create({
name: 'Invoice Payment Notification',
triggerConfig: {
eventType: 'PAYMENT_RECEIVED',
filters: {
'payload.amount': { gte: 100000 },
},
},
actions: [
{
type: 'webhook',
config: { webhookId: 'whk_abc123' },
},
{
type: 'email',
config: {
to: 'finance@example.com',
templateId: 'tmpl_receipt',
},
},
],
isActive: true,
});
console.log(workflow.id); // "wf_abc123"
The Python and Go create send their arguments as the request body, so use the route's camelCase field names. code (unique across every trigger: a code in use is 409 DUPLICATE) and triggerType (EVENT or SCHEDULE) are required, and each action is {type, config} with an upper-case type.
created = client.workflows.create(
name="Invoice Payment Notification",
code="PAYMENT_RECEIVED_NOTIFY",
triggerType="EVENT",
eventType="PAYMENT_RECEIVED",
conditions={"amount": {"gte": 100000}},
actions=[
{"type": "WEBHOOK", "config": {"url": "https://yourapp.com/hooks/invoice-paid"}},
{"type": "SEND_EMAIL", "config": {"recipient": "finance@example.com", "subject": "Invoice paid"}},
],
isActive=True,
)
trigger = created["trigger"]
trigger, err := client.Workflows.Create(map[string]interface{}{
"name": "Invoice Payment Notification",
"code": "PAYMENT_RECEIVED_NOTIFY",
"triggerType": "EVENT",
"eventType": "PAYMENT_RECEIVED",
"conditions": map[string]interface{}{
"amount": map[string]interface{}{"gte": 100000},
},
"actions": []map[string]interface{}{
{"type": "WEBHOOK", "config": map[string]interface{}{"url": "https://yourapp.com/hooks/invoice-paid"}},
{"type": "SEND_EMAIL", "config": map[string]interface{}{"recipient": "finance@example.com", "subject": "Invoice paid"}},
},
"isActive": true,
})
Get a workflow
const workflow = await client.workflows.get('wf_abc123');
workflow = client.workflows.get("wf_abc123")
workflow, err := client.Workflows.Get("wf_abc123")
Update a workflow
eventType is one of the values on Workflow Event Types; any other is 400 VALIDATION_ERROR. Sending the trigger's stored eventType back unchanged is always accepted.
const updated = await client.workflows.update('wf_abc123', {
name: 'High-Value Invoice Alert',
isActive: false,
});
updated = client.workflows.update(
"wf_abc123",
name="High-Value Invoice Alert",
isActive=False,
)
updated, err := client.Workflows.Update("wf_abc123", map[string]interface{}{
"name": "High-Value Invoice Alert",
"isActive": false,
})
An update changes only the fields it sends; null (Python None, Go nil) clears description, eventType, entityType, cronExpression, conditions, cooldownMinutes or maxExecutionsDay. The code, triggerType, eventType and entityType can change too: the trigger keeps its id and its executions, and each execution records the event it ran on. A code another trigger holds is 409 DUPLICATE, and an unknown event or entity type is 400 VALIDATION_ERROR. sourceApp cannot change: a trigger belongs to the service that created it, so any value other than your caller service is 400 VALIDATION_ERROR.
client.workflows.update("wf_abc123", code="INVOICE_SETTLED_NOTIFY", eventType="PAYMENT_RECEIVED", entityType=None)
_, err := client.Workflows.Update("wf_abc123", map[string]interface{}{
"code": "INVOICE_SETTLED_NOTIFY",
"eventType": "PAYMENT_RECEIVED",
"entityType": nil,
})
Scheduled triggers: entityQueryEndpoint
A scheduled trigger's entityQueryEndpoint is a platform-managed setting: only a platform key (no organization, issued from the dashboard) may set it — a tenant key gets 403 ENTITY_QUERY_NOT_ALLOWED — and anyone may clear it (null or ''). It must be an https:// URL on a public host; anything else is refused with 400 VALIDATION_ERROR (entityQueryEndpoint must use HTTPS, entityQueryEndpoint resolves to a non-public address, …). PlatformXe signs each request with X-Caldera-Signature / -Timestamp / -Delivery-Id over a body that names the exact target URL, triggerId and sourceApp, and sends no Authorization header; see Triggers & Creation for the receiver contract (verifyWebhookWithReplayKey, replay dedupe, target check).
Update and delete act only on your own triggers (sourceApp equal to your caller service); another service's trigger, or a platform trigger (no sourceApp), answers 404. On create, sourceApp is always your own caller service — a different value is 400 VALIDATION_ERROR unless you use a platform key.
On create, and on update when actions is sent, a SEND_EMAIL action's recipient must be one email address (ops@yourapp.com or "Ops <ops@yourapp.com>", at most 320 characters), or such an address written with {{field}} templates, in the address or the display name ({{guestEmail}}, Guest <{{guestEmail}}>, {{guestName}} <{{guestEmail}}>). A second address, text that is not part of the name or the address (junk {{x}}), an unclosed {{, a blank token or a value over 320 characters is 400 VALIDATION_ERROR with actions.<n>.config.recipient: must be one email address …, and nothing is stored. See Triggers & Creation.
await client.workflows.update('wf_abc123', {
entityQueryEndpoint: 'https://yourapp.com/api/internal/workflow-entities',
});
client.workflows.update("wf_abc123", entityQueryEndpoint="https://yourapp.com/api/internal/workflow-entities")
_, err := client.Workflows.Update("wf_abc123", map[string]interface{}{
"entityQueryEndpoint": "https://yourapp.com/api/internal/workflow-entities",
})
Delete a workflow
await client.workflows.delete('wf_abc123');
client.workflows.delete("wf_abc123")
result, err := client.Workflows.Delete("wf_abc123")
Evaluate
Test which workflows would match a given event type and payload. Returns the list of matching workflows and the actions that would execute.
const result = await client.workflows.evaluate({
eventType: 'PAYMENT_RECEIVED',
payload: {
invoiceId: 'inv_001',
amount: 250000,
currency: 'NGN',
},
});
console.log(result.matched); // Number of matching workflows
console.log(result.workflows); // Array of matched workflow details
result = client.workflows.evaluate(
event_type="PAYMENT_RECEIVED",
entity_data={"invoiceId": "inv_001", "amount": 250000, "currency": "NGN"},
entity_type="INVOICE", # optional, as are entity_id, source_app, metadata and dry_run
)
result, err := client.Workflows.EvaluateWithOptions(platformxe.WorkflowEvaluateInput{
EventType: "PAYMENT_RECEIVED",
EntityData: map[string]interface{}{
"invoiceId": "inv_001",
"amount": 250000,
"currency": "NGN",
},
DryRun: true,
})
eventType is one of the values on Workflow Event Types. entityData is your own parameters for the event, what the triggers' conditions and {{field}} templates read; for a business event type PlatformXe defines no fields. It is optional and the route reads {}, null and an absent field alike as none. What the SDKs send is unchanged since Python 1.12.0 and Go v1.12.0 (1.14.1 and v1.14.1 only document it): Python sends {} and omits None; Go's Evaluate / EvaluateWithOptions omit a nil or empty map.
The Python and Go SDKs send the event data as entityData, the field the route reads. Python's payload= keyword is a deprecated alias of entity_data (it warns); Go's Evaluate(eventType, data) sends data as entityData. Before this change both sent it as payload, which the route ignored, so no trigger saw the event data.
Each result item carries the trigger and, for a trigger that ran, its executionId and actionsExecuted. A step's status is SUCCESS, FAILED, SKIPPED or DEFERRED (an email declined for capacity, with a fixed reason in error; not retried). An item has no executionId when no execution could be recorded; its error says why. The Go SDK names the statuses WorkflowActionSucceeded … WorkflowActionDeferred (WorkflowExecutedAction.Status); the Python SDK exports WORKFLOW_ACTION_STATUSES. A recorded execution's steps are in the spelling of the engine that ran it (upper case for /evaluate, lower case for PlatformXe's own events and scheduled runs): the Python SDK's WORKFLOW_STEP_STATUSES holds both spellings and normalize_workflow_status() upper-cases one; the Go SDK's WorkflowActionResultStatus.Normalize() does the same. See Evaluate.
Dry run
Dry-run one trigger against entity data without running anything: POST /api/v1/workflows/{id} with { "entityData": { ... } }. The answer, under dryRun, says whether the trigger's conditions match (wouldMatch, with conditionsEvaluated per condition), which actions would run (actionsWouldExecute, and actionsPreview with each config interpolated), the trigger's config verdict (validation) and, when nothing would run, reason (another organisation's trigger, or one that does not exist, is "Trigger not found"). The route reads entityData only; it does not take an event type. To see which of your triggers an event would run, use evaluate with dryRun: true.
const dryRun = await client.workflows.dryRun('trg_abc123', {
eventType: 'PAYMENT_RECEIVED', // required by the TriggerContext type; not sent
entityData: { invoiceId: 'inv_001', amount: 250000 },
});
console.log(dryRun.wouldMatch, dryRun.actionsWouldExecute.length);
if (dryRun.reason === 'Trigger not found') {
// a wrong id, or another organisation's trigger: answered 200, not thrown
}
result = client.workflows.dry_run(
"trg_abc123",
entity_data={"invoiceId": "inv_001", "amount": 250000},
)
print(result["dryRun"]["wouldMatch"])
result, err := client.Workflows.DryRunEntityData("trg_abc123", map[string]interface{}{
"invoiceId": "inv_001",
"amount": 250000,
})
fmt.Println(result.WouldMatch, len(result.ActionsWouldExecute))
The TypeScript SDK's dryRun(triggerId, context) (1.16.2, pending release) returns the dryRun object itself (DryRunResult), not the { dryRun } wrapper. Python's dry_run(workflow_id, context) and Go's DryRun(triggerID, context) also take a context map. All three SDKs read the context by the same rule: a context whose every key is a trigger-context key (eventType, entityType, entityId, entityData, payload, metadata, sourceApp, dryRun, organizationId, callerService) and that carries an entityData (else payload) object sends that object; any other map is the entity data, sent whole. So the standard {eventType, entityType, entityId, entityData} context sends its entityData, and raw entity data that has its own payload field is sent whole. An empty trigger id is refused before any request (Python ValueError, Go ErrWorkflowIDRequired), and the id is URL-escaped. Before TypeScript 1.16.2, Python 1.13.0 and Go v1.13.0 each SDK posted to a /dry-run path the API does not have, so every call failed with 404; on an older TypeScript SDK, call the route directly.
Scopes required
| Method | Scope |
|---|---|
workflows.list() | workflows:read |
workflows.create() | workflows:write |
workflows.get() | workflows:read |
workflows.update() | workflows:write |
workflows.delete() | workflows:write |
workflows.evaluate() | workflows:write |
workflows.dryRun() / workflows.dry_run() / Workflows.DryRun() | workflows:write |