Triggers API

The Triggers API allows you to create, manage, and monitor workflow triggers. Triggers are events that automatically start your workflows, such as incoming messages, scheduled times, or external webhooks.

List Triggers

Retrieve a list of all triggers in your account.

Request

GET /v1/triggers

Parameters

ParameterTypeDescription
pageintegerPage number (default: 1)
limitintegerItems per page (default: 20, max: 100)
typestringFilter by trigger type (message, schedule, webhook, api)
statusstringFilter by status (active, inactive, paused)
workflow_idstringFilter by workflow ID

Response

{
  "data": [
    {
      "id": "trigger-123",
      "name": "WhatsApp Support Trigger",
      "type": "message",
      "status": "active",
      "workflow_id": "workflow-456",
      "channel": "whatsapp",
      "configuration": {
        "keywords": ["help", "support", "question"],
        "case_sensitive": false
      },
      "created_at": "2024-01-15T10:30:00Z",
      "updated_at": "2024-01-20T14:45:00Z",
      "execution_count": 250,
      "last_triggered": "2024-01-25T09:15:00Z"
    }
  ],
  "pagination": {
    "page": 1,
    "limit": 20,
    "total": 15,
    "pages": 1
  }
}

Get Trigger

Retrieve details of a specific trigger.

Request

GET /v1/triggers/{trigger_id}

Response

{
  "data": {
    "id": "trigger-123",
    "name": "WhatsApp Support Trigger",
    "type": "message",
    "status": "active",
    "workflow_id": "workflow-456",
    "channel": "whatsapp",
    "configuration": {
      "keywords": ["help", "support", "question"],
      "case_sensitive": false,
      "exact_match": false,
      "language": "en"
    },
    "created_at": "2024-01-15T10:30:00Z",
    "updated_at": "2024-01-20T14:45:00Z",
    "execution_count": 250,
    "last_triggered": "2024-01-25T09:15:00Z"
  }
}

Create Trigger

Create a new trigger for a workflow.

Request

POST /v1/triggers

Request Body

{
  "name": "Instagram Marketing Trigger",
  "type": "message",
  "workflow_id": "workflow-789",
  "channel": "instagram",
  "configuration": {
    "keywords": ["promo", "discount", "sale"],
    "case_sensitive": false,
    "exact_match": false,
    "language": "en"
  }
}

Response

{
  "data": {
    "id": "trigger-456",
    "name": "Instagram Marketing Trigger",
    "type": "message",
    "status": "active",
    "workflow_id": "workflow-789",
    "channel": "instagram",
    "configuration": {
      "keywords": ["promo", "discount", "sale"],
      "case_sensitive": false,
      "exact_match": false,
      "language": "en"
    },
    "created_at": "2024-01-25T11:00:00Z",
    "updated_at": "2024-01-25T11:00:00Z",
    "execution_count": 0,
    "last_triggered": null
  }
}

Update Trigger

Update an existing trigger.

Request

PUT /v1/triggers/{trigger_id}

Request Body

{
  "name": "Updated Instagram Marketing Trigger",
  "configuration": {
    "keywords": ["promo", "discount", "sale", "offer"],
    "case_sensitive": false,
    "exact_match": false,
    "language": "en"
  }
}

Response

{
  "data": {
    "id": "trigger-456",
    "name": "Updated Instagram Marketing Trigger",
    "type": "message",
    "status": "active",
    "workflow_id": "workflow-789",
    "channel": "instagram",
    "configuration": {
      "keywords": ["promo", "discount", "sale", "offer"],
      "case_sensitive": false,
      "exact_match": false,
      "language": "en"
    },
    "created_at": "2024-01-25T11:00:00Z",
    "updated_at": "2024-01-25T12:00:00Z",
    "execution_count": 0,
    "last_triggered": null
  }
}

Delete Trigger

Delete a trigger permanently.

Request

DELETE /v1/triggers/{trigger_id}

Response

{
  "message": "Trigger deleted successfully"
}

Trigger Types

Message Triggers

Trigger workflows based on incoming messages.

Configuration

{
  "type": "message",
  "configuration": {
    "keywords": ["help", "support", "question"],
    "case_sensitive": false,
    "exact_match": false,
    "language": "en",
    "channel": "whatsapp"
  }
}

Parameters

ParameterTypeDescription
keywordsarrayList of keywords to match
case_sensitivebooleanWhether matching is case sensitive
exact_matchbooleanWhether to match exact phrases
languagestringLanguage code for matching
channelstringCommunication channel to monitor

Schedule Triggers

Trigger workflows at specific times or intervals.

Configuration

{
  "type": "schedule",
  "configuration": {
    "cron_expression": "0 9 * * 1-5",
    "timezone": "UTC",
    "start_date": "2024-01-01T00:00:00Z",
    "end_date": "2024-12-31T23:59:59Z"
  }
}

Parameters

ParameterTypeDescription
cron_expressionstringCron expression for scheduling
timezonestringTimezone for the schedule
start_datestringWhen to start the schedule
end_datestringWhen to end the schedule

Webhook Triggers

Trigger workflows from external webhooks.

Configuration

{
  "type": "webhook",
  "configuration": {
    "url": "https://api.kaie.ai/v1/webhooks/trigger-123",
    "secret": "webhook-secret-key",
    "method": "POST",
    "headers": {
      "X-Custom-Header": "value"
    }
  }
}

Parameters

ParameterTypeDescription
urlstringWebhook URL for this trigger
secretstringSecret for webhook verification
methodstringHTTP method for webhook
headersobjectCustom headers for webhook

API Triggers

Trigger workflows via direct API calls.

Configuration

{
  "type": "api",
  "configuration": {
    "endpoint": "/v1/triggers/trigger-123/fire",
    "authentication": "api_key",
    "rate_limit": 100
  }
}

Parameters

ParameterTypeDescription
endpointstringAPI endpoint for triggering
authenticationstringAuthentication method
rate_limitintegerRate limit per hour

Trigger Management

Activate Trigger

Activate a trigger to start monitoring for events.

Request

POST /v1/triggers/{trigger_id}/activate

Response

{
  "data": {
    "id": "trigger-123",
    "status": "active",
    "activated_at": "2024-01-25T11:00:00Z"
  }
}

Deactivate Trigger

Deactivate a trigger to stop monitoring for events.

Request

POST /v1/triggers/{trigger_id}/deactivate

Response

{
  "data": {
    "id": "trigger-123",
    "status": "inactive",
    "deactivated_at": "2024-01-25T12:00:00Z"
  }
}

Pause Trigger

Temporarily pause a trigger without deactivating it.

Request

POST /v1/triggers/{trigger_id}/pause

Response

{
  "data": {
    "id": "trigger-123",
    "status": "paused",
    "paused_at": "2024-01-25T12:30:00Z"
  }
}

Resume Trigger

Resume a paused trigger.

Request

POST /v1/triggers/{trigger_id}/resume

Response

{
  "data": {
    "id": "trigger-123",
    "status": "active",
    "resumed_at": "2024-01-25T13:00:00Z"
  }
}

Trigger Executions

List Trigger Executions

Get a list of trigger executions.

Request

GET /v1/triggers/{trigger_id}/executions

Parameters

ParameterTypeDescription
pageintegerPage number (default: 1)
limitintegerItems per page (default: 20, max: 100)
statusstringFilter by status (success, failed, running)
start_datestringFilter executions after this date (ISO 8601)
end_datestringFilter executions before this date (ISO 8601)

Response

{
  "data": [
    {
      "id": "execution-789",
      "trigger_id": "trigger-123",
      "workflow_id": "workflow-456",
      "status": "success",
      "triggered_at": "2024-01-25T10:30:00Z",
      "completed_at": "2024-01-25T10:30:15Z",
      "duration_ms": 15000,
      "input": {
        "message": "I need help with my order",
        "customer_id": "customer-789",
        "channel": "whatsapp"
      },
      "output": {
        "workflow_execution_id": "workflow-execution-123"
      }
    }
  ],
  "pagination": {
    "page": 1,
    "limit": 20,
    "total": 50,
    "pages": 3
  }
}

Get Trigger Execution Details

Get detailed information about a specific trigger execution.

Request

GET /v1/triggers/{trigger_id}/executions/{execution_id}

Response

{
  "data": {
    "id": "execution-789",
    "trigger_id": "trigger-123",
    "workflow_id": "workflow-456",
    "status": "success",
    "triggered_at": "2024-01-25T10:30:00Z",
    "completed_at": "2024-01-25T10:30:15Z",
    "duration_ms": 15000,
    "input": {
      "message": "I need help with my order",
      "customer_id": "customer-789",
      "channel": "whatsapp",
      "metadata": {
        "user_agent": "WhatsApp/2.23.1.74",
        "timestamp": "2024-01-25T10:30:00Z"
      }
    },
    "output": {
      "workflow_execution_id": "workflow-execution-123",
      "workflow_status": "success"
    },
    "error": null
  }
}

Trigger Analytics

Get Trigger Metrics

Retrieve analytics data for a specific trigger.

Request

GET /v1/triggers/{trigger_id}/metrics

Parameters

ParameterTypeDescription
start_datestringStart date for metrics (ISO 8601)
end_datestringEnd date for metrics (ISO 8601)
granularitystringData granularity (hour, day, week, month)

Response

{
  "data": {
    "trigger_id": "trigger-123",
    "period": {
      "start_date": "2024-01-01T00:00:00Z",
      "end_date": "2024-01-31T23:59:59Z"
    },
    "metrics": {
      "total_executions": 250,
      "successful_executions": 240,
      "failed_executions": 10,
      "success_rate": 0.96,
      "average_duration_ms": 5000,
      "unique_customers": 150,
      "channel_breakdown": {
        "whatsapp": 200,
        "instagram": 50
      }
    },
    "daily_metrics": [
      {
        "date": "2024-01-01",
        "executions": 8,
        "success_rate": 0.95,
        "average_duration_ms": 4800
      }
    ]
  }
}

Error Handling

Common Error Codes

Status CodeError CodeDescription
400INVALID_TRIGGER_CONFIGTrigger configuration is invalid
400MISSING_REQUIRED_FIELDRequired field is missing
404TRIGGER_NOT_FOUNDTrigger does not exist
409TRIGGER_ALREADY_EXISTSTrigger with this name already exists
422INVALID_CRON_EXPRESSIONCron expression is invalid
500TRIGGER_EXECUTION_FAILEDTrigger execution failed

Error Response Format

{
  "error": {
    "code": "INVALID_TRIGGER_CONFIG",
    "message": "Trigger configuration is invalid",
    "details": "Keywords array cannot be empty",
    "field": "configuration.keywords"
  }
}

Rate Limiting

Trigger API endpoints are subject to rate limiting:
  • List/Get operations: 1000 requests per hour
  • Create/Update operations: 100 requests per hour
  • Delete operations: 50 requests per hour
  • Execution operations: 500 requests per hour

Next Steps

Explore more API endpoints: