API & Webhooks
Programmatically interact with your agents through APIs and webhooks
Kapso provides powerful programmatic interfaces to integrate your agents with external systems, enabling automated workflows and real-time communication.
API Overview
The Kapso API enables you to:
- Trigger agent executions programmatically
- Retrieve execution status and results
- Manage agent configurations
- Access conversation history
Authentication
All API requests require authentication using your Project API Key:
Find your API keys in your Project settings under “API Keys”. Keep these keys secure and never expose them in client-side code.
For complete endpoint documentation, see the API Reference.
Agent Webhooks
Webhooks allow two-way communication: your systems can trigger Kapso agents, and Kapso agents can notify your systems.
Incoming Webhooks (Triggering Agents)
Use incoming webhooks to start an agent’s execution flow from your application (e.g., backend, CRM).
-
Endpoint: Each agent has a unique webhook URL.
-
Authentication: Include your Project API Key in the
X-API-Key
request header. -
Request Body (Optional): Send initial data in the JSON payload.
-
Example (Node.js):
Outbound Webhooks (Agent Notifications)
Configure your agents to send real-time notifications to your systems when important events occur during execution.
Configuration
- Navigate to your agent’s “API & Webhooks” settings
- Add webhook endpoints for the events you want to monitor
- Configure a Secret Key for request verification
- Select which events to subscribe to
Supported Events
Execution Started
agent_execution_started
Fired when an agent begins processing
Execution Ended
agent_execution_ended
Fired when an agent completes successfully
Execution Failed
agent_execution_failed
Fired when an agent encounters an error
Handoff Required
agent_execution_handoff
Fired when human intervention is needed
Security & Verification
Every webhook request includes an X-Webhook-Signature
header containing an HMAC SHA-256 signature of the request body. Verify this signature using your configured Secret Key to ensure authenticity.
Webhook Payloads
All webhook payloads include base execution data plus event-specific information:
Base Payload Structure
Event-Specific Data
Handoff Event includes handoff details:
Failed Event includes error information:
Webhook Best Practices
Important considerations:
- Respond quickly (within 5 seconds) with a 2xx status code
- Process webhook data asynchronously if needed
- Store the webhook secret securely
- Always verify webhook signatures
- Implement idempotency handling using the provided idempotency key
WhatsApp Webhooks
Kapso provides real-time webhooks for WhatsApp messaging events, enabling you to build powerful integrations and automate workflows based on WhatsApp conversations.
Configuring WhatsApp Webhooks
- Navigate to your WhatsApp configuration settings
- Go to the “Webhooks” tab
- Click “Add Webhook” to create a new webhook endpoint
- Configure the following:
- URL: Your endpoint that will receive webhook notifications
- Events: Select which events you want to subscribe to
- Secret Key: Auto-generated or provide your own (used for HMAC signature verification)
- Custom Headers: Optional additional headers for authentication
WhatsApp Webhook Events
Message Received
whatsapp.message.received
Fired when a new WhatsApp message is received from a customer
Message Sent
whatsapp.message.sent
Fired when your system sends a message to a customer
Message Delivered
whatsapp.message.delivered
Fired when a message is successfully delivered to the recipient’s device
Message Read
whatsapp.message.read
Fired when the recipient reads your message
Message Failed
whatsapp.message.failed
Fired when a message fails to deliver
Conversation Created
whatsapp.conversation.created
Fired when a new WhatsApp conversation is initiated
WhatsApp Webhook Headers
Every WhatsApp webhook request includes these headers:
WhatsApp Webhook Payloads
Message Event Payload
For message-related events (received
, sent
, delivered
, read
, failed
):
Conversation Created Payload
For the whatsapp.conversation.created
event:
Message Types
The message_type
field can be one of:
text
- Plain text messageimage
- Image attachmentvideo
- Video attachmentaudio
- Audio/voice messagedocument
- Document attachmentlocation
- Location sharingsticker
- WhatsApp sticker
Verifying WhatsApp Webhooks
Always verify the webhook signature to ensure the request is authentic:
Testing WhatsApp Webhooks
You can test your webhook endpoints directly from the Kapso interface:
- Go to your WhatsApp webhook configuration
- Click the “Test Webhook” button
- Select an event type to test
- Review the sample payload that will be sent
- Click “Send Test” to trigger a test webhook
The test will use realistic sample data that matches the exact structure of production webhooks.
Webhook Reliability
Kapso implements several features to ensure reliable webhook delivery:
- Retries: Failed webhooks are retried up to 3 times with exponential backoff (1 minute, 4 minutes, 9 minutes)
- Timeout: Webhook requests timeout after 30 seconds
- Idempotency: Each event has a unique idempotency key to prevent duplicate processing
- Delivery Tracking: All webhook deliveries are logged with full request/response details
Best Practices for WhatsApp Webhooks
- Handle Events Asynchronously: Process webhook data in background jobs to respond quickly
- Implement Idempotency: Use the
X-Idempotency-Key
header to prevent processing duplicates - Monitor Failures: Set up alerts for webhook delivery failures
- Secure Your Endpoint: Always verify signatures and use HTTPS
- Handle All Event Types: Even if you only need certain events now, handle all types gracefully