Webhooks
Receive real-time notifications about events in your application
Webhooks allow you to subscribe to important events in the AXIFI platform. Instead of polling the API, we'll send you real-time notifications when events occur.
Get notified instantly when events occur
Guaranteed delivery with automatic retries
Signed payloads for verification
1. Create an Endpoint
Create an HTTPS endpoint that can receive POST requests from our servers.
POST /webhooks/axifi
Content-Type: application/json
X-Webhook-Signature: sha256=xxx...
{
"event": "compound.created",
"timestamp": "2024-01-15T10:30:45Z",
"data": { ... }
}
2. Register in Dashboard
Go to your developer dashboard and configure webhook endpoints for each event type.
3. Verify Signatures
Always verify webhook signatures to ensure requests are from AXIFI.
Triggered when a new compound is added to the database
Payload
{
"event": "compound.created",
"timestamp": "2024-01-15T10:30:45Z",
"data": {
"id": "compound-123",
"name": "Aspirin",
"category": "analgesic",
"efficacy": 0.92
}
}Each webhook includes an X-Webhook-Signature header containing an HMAC-SHA256 signature of the payload. Verify this signature before processing the webhook.
Verification Example (Node.js)
const crypto = require('crypto');
function verifyWebhookSignature(payload, signature, secret) {
const expectedSignature = 'sha256=' + crypto
.createHmac('sha256', secret)
.update(payload)
.digest('hex');
return crypto.timingSafeEqual(
Buffer.from(signature),
Buffer.from(expectedSignature)
);
}
// In your webhook handler
app.post('/webhooks/axifi', (req, res) => {
const signature = req.headers['x-webhook-signature'];
const payload = JSON.stringify(req.body);
if (!verifyWebhookSignature(payload, signature, process.env.WEBHOOK_SECRET)) {
return res.status(401).json({ error: 'Unauthorized' });
}
// Process webhook...
res.json({ ok: true });
});
Verification Example (Python)
import hmac
import hashlib
def verify_webhook_signature(payload, signature, secret):
expected_signature = 'sha256=' + hmac.new(
secret.encode(),
payload,
hashlib.sha256
).hexdigest()
return hmac.compare_digest(signature, expected_signature)
@app.route('/webhooks/axifi', methods=['POST'])
def handle_webhook():
signature = request.headers.get('X-Webhook-Signature')
payload = request.get_data()
if not verify_webhook_signature(payload, signature, os.environ['WEBHOOK_SECRET']):
return {'error': 'Unauthorized'}, 401
# Process webhook...
return {'ok': True}
Retry Schedule
Webhooks are considered delivered when your endpoint returns a 2xx status code. If your endpoint is unreachable or returns a non-2xx response, we'll retry according to the schedule above.
- Always verify signaturesNever trust webhook data without signature verification
- Respond quicklyWebhooks timeout after 30 seconds. Process asynchronously
- Handle duplicatesUse event IDs to prevent duplicate processing
- Use HTTPS onlyAll webhook endpoints must use HTTPS