Webhooks API
Webhooks allow you to receive real-time notifications about events in your Kaie workflows. Use webhooks to integrate with external systems, trigger custom actions, or build real-time dashboards.Overview
Webhooks are HTTP callbacks that Kaie sends to your application when specific events occur. Common use cases include:- Notifying external systems of workflow completions
- Triggering custom actions based on customer interactions
- Building real-time monitoring dashboards
- Integrating with third-party services
Webhook Events
Available Events
Event Type | Description | When Triggered |
---|---|---|
workflow.started | Workflow execution started | When a workflow begins execution |
workflow.completed | Workflow execution completed | When a workflow finishes (success or failure) |
workflow.failed | Workflow execution failed | When a workflow fails with an error |
message.received | New message received | When a customer sends a message |
message.sent | Message sent to customer | When a message is sent to a customer |
trigger.activated | Trigger activated | When a trigger fires |
customer.created | New customer created | When a new customer is added |
customer.updated | Customer information updated | When customer data is modified |
Event Payload Structure
All webhook events follow a consistent payload structure:Webhook Management
Create Webhook
Create a new webhook endpoint.Request
Request Body
Response
List Webhooks
Retrieve all webhooks in your account.Request
Parameters
Parameter | Type | Description |
---|---|---|
page | integer | Page number (default: 1) |
limit | integer | Items per page (default: 20, max: 100) |
active | boolean | Filter by active status |
event_type | string | Filter by event type |
Response
Get Webhook
Retrieve details of a specific webhook.Request
Response
Update Webhook
Update an existing webhook.Request
Request Body
Response
Delete Webhook
Delete a webhook permanently.Request
Response
Webhook Security
Signature Verification
All webhook requests include an HMAC-SHA256 signature in theX-Kaie-Signature
header for verification.
Verification Process
- Extract the signature from the
X-Kaie-Signature
header - Create a hash of the request body using your webhook secret
- Compare the signatures using a constant-time comparison
Example Implementation
Python Example
IP Whitelisting
For additional security, you can whitelist Kaie’s IP addresses:203.0.113.0/24
- Primary webhook IP range198.51.100.0/24
- Secondary webhook IP range
Webhook Delivery
Delivery Process
- Event Occurs: An event triggers in your Kaie workflow
- Webhook Queued: The webhook is added to the delivery queue
- HTTP Request: Kaie sends a POST request to your endpoint
- Response Handling: Your endpoint responds with HTTP status code
- Retry Logic: If delivery fails, retry according to policy
Response Codes
Status Code | Behavior |
---|---|
200 OK | Webhook delivered successfully |
201 Created | Webhook delivered successfully |
400 Bad Request | Invalid request format (not retried) |
401 Unauthorized | Authentication failed (not retried) |
403 Forbidden | Access denied (not retried) |
404 Not Found | Endpoint not found (not retried) |
429 Too Many Requests | Rate limited (retried with backoff) |
500 Internal Server Error | Server error (retried) |
502 Bad Gateway | Gateway error (retried) |
503 Service Unavailable | Service unavailable (retried) |
504 Gateway Timeout | Gateway timeout (retried) |
Retry Policy
Webhooks are retried according to the configured retry policy:- Max Retries: Maximum number of retry attempts (default: 3)
- Retry Delay: Delay between retries in milliseconds (default: 1000)
- Exponential Backoff: Delay increases exponentially with each retry
- Max Delay: Maximum delay between retries (default: 30000ms)
Webhook Testing
Test Webhook
Test a webhook endpoint to verify it’s working correctly.Request
Request Body
Response
Webhook Logs
View delivery logs for a webhook.Request
Parameters
Parameter | Type | Description |
---|---|---|
page | integer | Page number (default: 1) |
limit | integer | Items per page (default: 20, max: 100) |
status | string | Filter by delivery status |
start_date | string | Filter logs after this date |
end_date | string | Filter logs before this date |
Response
Error Handling
Common Error Codes
Status Code | Error Code | Description |
---|---|---|
400 | INVALID_WEBHOOK_URL | Webhook URL is invalid |
400 | INVALID_EVENT_TYPES | Event types are invalid |
400 | INVALID_RETRY_POLICY | Retry policy is invalid |
404 | WEBHOOK_NOT_FOUND | Webhook does not exist |
409 | WEBHOOK_ALREADY_EXISTS | Webhook with this URL already exists |
422 | WEBHOOK_VALIDATION_FAILED | Webhook validation failed |
Error Response Format
Best Practices
Webhook Implementation
Endpoint Design
Endpoint Design
- Use HTTPS endpoints only
- Implement idempotency for duplicate events
- Respond quickly (within 5 seconds)
- Use appropriate HTTP status codes
Security
Security
- Verify webhook signatures
- Use IP whitelisting when possible
- Implement rate limiting
- Log all webhook deliveries
Performance Optimization
Processing
Processing
- Process webhooks asynchronously
- Use message queues for high volume
- Implement proper error handling
- Monitor webhook performance
Monitoring
Monitoring
- Track delivery success rates
- Monitor response times
- Set up alerts for failures
- Regular testing and validation