LendWorksLendWorksDocs

Automations

List automation templates, trigger automation runs, and cancel in-progress instances.

Automations allow you to define reusable workflow templates that execute business logic automatically. The API provides endpoints to list templates, trigger new runs, and cancel in-progress instances.

List Automation Templates

GET /v1/automations

Returns a paginated list of automation templates with execution statistics.

Query Parameters

ParameterTypeDefaultDescription
pageinteger1Page number
limitinteger20Items per page (max 100)

Example Request

curl -H "Authorization: Bearer lw_live_xxxx" \
     "https://api.lend.works/v1/automations?limit=10"

Example Response

{
  "data": [
    {
      "id": "tmpl_a1b2c3d4-1234-5678-9abc-def012345678",
      "type": "automation_template",
      "attributes": {
        "name": "New Lead Welcome Sequence",
        "description": "Sends welcome email and assigns to advisor when a new lead is created",
        "triggerType": "lead.created",
        "isActive": true,
        "stats": {
          "totalRuns": 342,
          "successCount": 338,
          "failureCount": 4,
          "lastRunAt": "2025-01-15T14:30:00Z"
        },
        "createdAt": "2024-09-01T10:00:00Z",
        "updatedAt": "2025-01-10T08:00:00Z"
      }
    }
  ],
  "meta": {
    "total": 12,
    "page": 1,
    "limit": 10,
    "hasMore": true,
    "requestId": "a10b20c3-d4e5-4f67-8901-234567890abc"
  }
}

Trigger an Automation

POST /v1/automations/{id}/trigger

Manually trigger an automation template to create a new instance. This is useful for testing or one-off execution.

Path Parameters

ParameterTypeDescription
idUUIDTemplate ID to trigger

Request Body (Optional)

FieldTypeDescription
entityTypestringType of entity to pass to the automation. Defaults to api_trigger
entityIdstringID of the entity. Defaults to the template ID

Example Request

curl -X POST https://api.lend.works/v1/automations/tmpl_a1b2c3d4-1234-5678-9abc-def012345678/trigger \
  -H "Authorization: Bearer lw_live_xxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "entityType": "lead",
    "entityId": "d290f1ee-6c54-4b01-90e6-d701748f0851"
  }'

Response — 201 Created

{
  "data": {
    "id": "inst_f1e2d3c4-1234-5678-9abc-def012345678",
    "type": "automation_instance",
    "attributes": {
      "templateId": "tmpl_a1b2c3d4-...",
      "status": "running",
      "entityType": "lead",
      "entityId": "d290f1ee-...",
      "startedAt": "2025-01-15T14:35:00Z",
      "createdAt": "2025-01-15T14:35:00Z",
      "updatedAt": "2025-01-15T14:35:00Z"
    }
  },
  "meta": {
    "requestId": "b21c31d4-e5f6-4a78-9012-345678901bcd"
  }
}

Cancel an Automation Instance

POST /v1/automations/{id}/cancel

Cancel a running automation instance. Only in-progress instances can be cancelled. Note: this takes an instance ID (returned from trigger), not a template ID.

Path Parameters

ParameterTypeDescription
idUUIDInstance ID (not template ID)

Example Request

curl -X POST https://api.lend.works/v1/automations/inst_f1e2d3c4-1234-5678-9abc-def012345678/cancel \
  -H "Authorization: Bearer lw_live_xxxx"

Response — 200 OK

{
  "data": {
    "type": "cancel_result",
    "attributes": {
      "success": true
    }
  },
  "meta": {
    "requestId": "c32d42e5-f6a7-4b89-0123-456789012cde"
  }
}

Errors

StatusCodeDescription
403FORBIDDENAPI key lacks permission
404NOT_FOUNDTemplate or instance not found
422VALIDATION_ERRORInvalid trigger payload