Corteksa
GuidesAutomation

Examples

Automation — Examples

Copy-paste, working requests. BASE = https://<workspace>.corteksa.com/api/v1, JWT = your admin login token.

Create a workflow (status change → WhatsApp)

Fire when a deal's status becomes won, only for deals over 5,000, and message the customer.

cURL

curl -X POST "$BASE/workflow" \
  -H "Authorization: Bearer $JWT" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Deal won → thank the customer",
    "trigger_type": "status_changed",
    "trigger_config": {
      "object_slug": "deals",
      "status_field_slug": "deal_status",
      "from_status": null,
      "to_status": "won"
    },
    "filter_config": {
      "condition_groups": [
        { "conditions": [
          { "field_slug": "amount", "operator": "greater_than", "value": 5000 }
        ] }
      ]
    },
    "action_type": "send_message",
    "action_config": {
      "session_slug": "sales-wa",
      "phone_field_slug": "phone",
      "message_template": "Congrats {{name}}! Your order is confirmed 🎉",
      "link_to_record": true
    }
  }'

The response data.slug (e.g. deal-won-thank-the-customer-l9xk2) identifies the workflow. It starts paused.

JavaScript (fetch)

const res = await fetch(`${BASE}/workflow`, {
  method: 'POST',
  headers: { Authorization: `Bearer ${jwt}`, 'Content-Type': 'application/json' },
  body: JSON.stringify(workflow),
});
const { data } = await res.json();
const slug = data.slug;

Activate it

curl -X PUT "$BASE/workflow/$SLUG/toggle" \
  -H "Authorization: Bearer $JWT"

Returns { message: "Workflow activated successfully", data: { is_active: true, ... } }. A 400 here with code: "SESSION_NOT_LINKED_TO_OBJECT" means the messaging session needs an object link — see Troubleshooting.

List executions (paginated)

curl "$BASE/workflow/$SLUG/executions?page=1&limit=25&status=failed" \
  -H "Authorization: Bearer $JWT"

Each row: status (completed/failed/skipped), object_slug, record_slug, filter_result, filter_reason, action_result, error_message, duration_ms, executed_at. pagination is at the top level.

Retry a failed execution

curl -X POST "$BASE/workflow/$SLUG/retry/1841" \
  -H "Authorization: Bearer $JWT"

Only executions with status: "failed" can be retried.

Create a workflow from a template

curl "$BASE/workflow/templates?category=sales" -H "Authorization: Bearer $JWT"

curl -X POST "$BASE/workflow/templates/$TEMPLATE_SLUG/use" \
  -H "Authorization: Bearer $JWT" -H "Content-Type: application/json" \
  -d '{ "name": "My copy of this template" }'

Watch runs in real time

import { io } from 'socket.io-client';

const socket = io(`${WS_HOST}/workflow/events`, {
  auth: { token: jwt },
  query: { tenantDb },
  transports: ['websocket'],
});

socket.on('connected', () => console.log('live'));
socket.on('workflow:execution.completed', (e) => console.log('ran', e.workflowId));
socket.on('workflow:execution.failed', (e) => console.warn('failed', e.error));
socket.on('workflow:stats.updated', (e) => refresh(e.workflowId));

On this page