Receive real-time notifications about events in your system
Webhooks are HTTP callbacks that allow you to receive real-time notifications when specific events occur in your Connect2Print system.
Benefits of Webhooks:
Connect2Print sends webhooks for the following events:
Receive notifications about order changes:
order.created - A new order has been createdorder.updated - An order has been updatedorder.completed - An order has been completedorder.cancelled - An order has been cancelledorder.shipped - An order has been shippedinvoice.created - A new invoice has been createdinvoice.sent - An invoice has been sentinvoice.paid - An invoice has been paidquote.created - A new quote has been createdquote.accepted - A quote has been acceptedquote.rejected - A quote has been rejectedproduction.job.created - A new production job has been createdproduction.job.completed - A production job is completecustomer.created - A new customer has been createdshipment.delivered - A shipment has been deliveredstock.low - Stock level is lowCreate and configure webhooks from the admin panel:
Store the webhook secret securely - it's used to validate webhook signatures.
All webhooks send data in the following format:
Payload Fields:
id - Unique ID for this webhook deliveryevent - Event type (e.g., "order.created")timestamp - ISO 8601 timestampdata - Event-specific data (varies by event type){
"id": "wh_1a2b3c4d5e6f",
"event": "order.created",
"timestamp": "2024-01-15T10:30:00Z",
"data": {
"order": {
"id": 123,
"order_number": "ORD-2024-001",
"status": "pending",
"total": 499.00,
"customer": {
"id": 456,
"email": "customer@example.com"
}
}
}
}
All webhooks include an X-Webhook-Signature header that you MUST validate to ensure the request comes from Connect2Print.
X-Webhook-Signature// PHP $signature = $_SERVER['HTTP_X_WEBHOOK_SIGNATURE']; $body = file_get_contents('php://input'); $secret = 'your_webhook_secret'; $calculated = hash_hmac('sha256', $body, $secret); if (!hash_equals($signature, $calculated)) { http_response_code(401); die('Invalid signature'); } // Signature is valid, process the webhook $data = json_decode($body, true);
// Node.js const crypto = require('crypto'); function validateWebhook(body, signature, secret) { const calculated = crypto .createHmac('sha256', secret) .update(body) .digest('hex'); return crypto.timingSafeEqual( Buffer.from(signature), Buffer.from(calculated) ); }
# Python import hmac import hashlib def validate_webhook(body, signature, secret): calculated = hmac.new( secret.encode(), body.encode(), hashlib.sha256 ).hexdigest() return hmac.compare_digest(signature, calculated)
Best practices for handling webhooks:
Respond with HTTP 200 status immediately. Process event data asynchronously in the background.
Never trust the data without validating the webhook signature first.
The same event may be sent multiple times. Use the event id to deduplicate.
Webhooks are not necessarily sent in chronological order. Use timestamp to sort.
Your endpoint must respond within 10 seconds, or it will be considered a failure.
Log incoming webhooks for debugging and audit trail.
If your endpoint fails or doesn't respond, Connect2Print automatically retries:
Retry Schedule:
You can view webhook delivery status and retry history in the admin panel.
Test your webhooks before production setup:
Use a tool like webhook.site to inspect webhook payloads.
Use the "Send Test Event" feature in the admin panel to send a sample payload.
Use ngrok to expose your local server for webhook deliveries.
Send a test webhook programmatically:
POST /api/v1/webhooks/{id}/test Authorization: Bearer YOUR_API_KEY // Example response { "success": true, "message": "Test webhook sent" }
Now that you understand webhooks, explore related topics: