Typical Use Cases
- CRM synchronization: Keep customer profiles updated across platforms.
- Marketing automation: Trigger custom emails, messages, or campaigns.
- Customer engagement tracking: Monitor opens, clicks, and reads.
- Analytics: Push data to internal analytics dashboards.
- Internal workflow automation: Automate business logic when contacts or events change.
Creating a Webhook
To create a webhook, follow these steps in your dashboard:- Navigate to Settings → Webhooks.
- Click Add Webhook.
- Fill in the required configuration options.
Webhook Configuration
Webhook URL
The public HTTPS endpoint that will receive webhook requests.- Example:
https://example.com/api/webhooks/cocoonmail
We highly recommend using HTTPS endpoints to ensure webhook payloads are encrypted in transit. Your endpoint must respond within the timeout window and return an HTTP
2xx status code for successful delivery.Authorization (Optional)
An optional authorization header sent with every webhook request to verify that the request is coming from Cocoonmail.- Examples:
Bearer YOUR_SECRET_TOKENBasic xxxxxxxxx
Select Events
Choose one or more events to subscribe to. You can subscribe to the following event types:Contact Events
contact.createdcontact.updatedcontact.deleted
Email Events
email.sentemail.openedemail.clickedemail.bouncedemail.subscribedemail.unsubscribed
WhatsApp Events
whatsapp.sentwhatsapp.failedwhatsapp.readwhatsapp.engagedwhatsapp.subscribedwhatsapp.unsubscribedwhatsapp.message_received
Only the selected events will be delivered to your webhook URL.
Headers and Payloads
Reserved Headers
Every webhook automatically includes several Cocoonmail headers that cannot be removed. Depending on the event type, additional headers are automatically included. In the Webhook Builder interface, these are categorized under:- Contact Event Headers
- Email Event Headers
- WhatsApp Event Headers
Custom Headers
You may include your own HTTP headers to be sent alongside Cocoonmail’s reserved headers.- Examples:
x-app-version: 2.0x-tenant: productionx-workspace: workspace_123
Custom Payload
By default, Cocoonmail sends a standard JSON payload. You can customize the payload by adding additional fields in the Payload Builder. This allows you to:- Simplify integrations
- Include only required fields
- Create payloads compatible with third-party systems
Delivery
Webhooks are delivered using an HTTP POST request.Example Request
Payload
Best Practices
To ensure reliable webhook delivery and processing:- Return HTTP 200 immediately: Acknowledge receipt of the webhook before performing long-running or downstream tasks.
- Process webhooks asynchronously: Use a queue or background worker to process the payload.
- Validate authorization headers: Ensure requests are authentic before taking action.
- Log webhook requests: Store raw payloads and headers to assist with debugging.
- Retry logic: Implement retries for downstream systems in case of failures.
- Use HTTPS: Secure your webhook endpoint with SSL/TLS.