Webhooks
Receive real-time notifications when events happen in codmir.
Real-time
Events delivered instantly when they occur.
Secure
HMAC signatures to verify authenticity.
Reliable
Automatic retries with exponential backoff.
Setting Up Webhooks
1
Create a Webhook Endpoint
Create an endpoint in your application to receive webhook events. The endpoint must accept POST requests and return a 2xx status code.
app.post('/webhooks/codmir', (req, res) => {
const event = req.body;
switch (event.type) {
case 'ticket.created':
// Handle new ticket
break;
case 'ticket.updated':
// Handle ticket update
break;
}
res.status(200).send('OK');
});2
Register Your Webhook
Register your webhook endpoint via the API or dashboard.
curl -X POST "https://api.codmir.com/v1/webhooks" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://your-app.com/webhooks/codmir",
"events": ["ticket.created", "ticket.updated"],
"secret": "your-webhook-secret"
}'3
Verify Signatures
Always verify webhook signatures to ensure requests are from codmir.
import crypto from 'crypto';
function verifySignature(payload: string, signature: string, secret: string) {
const expected = crypto
.createHmac('sha256', secret)
.update(payload)
.digest('hex');
return crypto.timingSafeEqual(
Buffer.from(signature),
Buffer.from(`sha256=${expected}`)
);
}Available Events
| Event | Description |
|---|---|
| ticket.created | A new ticket was created |
| ticket.updated | A ticket was updated |
| ticket.deleted | A ticket was deleted |
| ticket.status_changed | A ticket status was changed |
| ticket.assigned | A ticket was assigned |
| comment.created | A comment was added to a ticket |
| project.created | A new project was created |
| member.added | A member was added to a project |
Payload Structure
{
"id": "evt_abc123",
"type": "ticket.created",
"timestamp": "2024-01-15T10:30:00Z",
"data": {
"ticket": {
"id": "tkt_xyz789",
"title": "Bug in login flow",
"status": "open",
"priority": "high",
// ... more fields
},
"project": {
"id": "proj_def456",
"name": "Main App"
},
"user": {
"id": "usr_ghi012",
"name": "John Doe"
}
}
}