Webhooks provide a way for external systems to receive real-time notifications when specific events occur in the Universal Bookshelf platform. This enables seamless integration with third-party services, analytics platforms, and custom applications.
user.registered - New user registrationuser.updated - User profile updatesuser.deleted - User account deletionuser.login - User login activitybook.created - New book publicationbook.updated - Book information updatesbook.published - Book goes livebook.unpublished - Book taken offlinebook.deleted - Book removalorder.created - New order placementorder.paid - Order payment confirmationorder.shipped - Order shipping notificationorder.delivered - Order delivery confirmationorder.cancelled - Order cancellationorder.refunded - Order refund processingpayment.succeeded - Successful paymentpayment.failed - Failed payment attemptpayment.refunded - Payment refundpayment.disputed - Payment disputedownload.started - eBook download initiateddownload.completed - eBook download finisheddownload.failed - Download failureCreate a new webhook subscription
{
"url": "https://yourdomain.com/webhook",
"events": ["order.created", "payment.succeeded"],
"description": "Order and payment notifications",
"secret": "your_webhook_secret"
}
{
"status": true,
"message": "Webhook created successfully",
"webhook": {
"id": 1,
"url": "https://yourdomain.com/webhook",
"events": ["order.created", "payment.succeeded"],
"status": "active",
"created_at": "2024-01-01T00:00:00.000000Z"
}
}
List all webhook subscriptions
Authorization: Bearer <your_jwt_token>
{
"status": true,
"webhooks": [
{
"id": 1,
"url": "https://yourdomain.com/webhook",
"events": ["order.created", "payment.succeeded"],
"status": "active",
"created_at": "2024-01-01T00:00:00.000000Z"
}
]
}
Update webhook subscription
Authorization: Bearer <your_jwt_token>
{
"events": ["order.created", "payment.succeeded", "book.published"],
"description": "Updated webhook description"
}
Delete webhook subscription
Authorization: Bearer <your_jwt_token>
{
"status": true,
"message": "Webhook deleted successfully"
}
All webhook payloads follow a consistent structure:
{
"id": "webhook_event_id",
"event": "order.created",
"created_at": "2024-01-01T00:00:00.000000Z",
"data": {
// Event-specific data
},
"api_version": "1.0"
}
{
"id": "evt_123456789",
"event": "order.created",
"created_at": "2024-01-01T00:00:00.000000Z",
"data": {
"order_id": 12345,
"user_id": 67890,
"total_amount": 29.99,
"currency": "USD",
"items": [
{
"book_id": 111,
"title": "Sample Book",
"format": "ebook",
"price": 29.99
}
],
"status": "pending"
},
"api_version": "1.0"
}
{
"id": "evt_987654321",
"event": "payment.succeeded",
"created_at": "2024-01-01T00:00:00.000000Z",
"data": {
"payment_id": "pi_123456789",
"order_id": 12345,
"amount": 29.99,
"currency": "USD",
"payment_method": "stripe",
"status": "succeeded"
},
"api_version": "1.0"
}
The platform sends webhooks with a signature header for verification:
// Webhook signature header
X-Webhook-Signature: sha256=abc123def456...
// PHP example
function verifyWebhookSignature($payload, $signature, $secret) {
$expectedSignature = 'sha256=' . hash_hmac('sha256', $payload, $secret);
return hash_equals($expectedSignature, $signature);
}
// Verify the webhook
$payload = file_get_contents('php://input');
$signature = $_SERVER['HTTP_X_WEBHOOK_SIGNATURE'] ?? '';
$secret = 'your_webhook_secret';
if (!verifyWebhookSignature($payload, $signature, $secret)) {
http_response_code(400);
exit('Invalid signature');
}
Return any 2xx status code to confirm successful webhook processing:
200 OK - Standard success response201 Created - Resource created successfully202 Accepted - Request accepted for processingAny 4xx or 5xx status code will trigger a retry:
400 Bad Request - Invalid payload500 Internal Server Error - Server error503 Service Unavailable - Service temporarily unavailableSend a test webhook to verify your endpoint
Authorization: Bearer <your_jwt_token>
{
"webhook_id": 1,
"test_event": "order.created"
}
For local development, use ngrok to expose your local server:
# Install ngrok
npm install -g ngrok
# Expose local server
ngrok http 8000
# Use the ngrok URL as your webhook endpoint
# https://abc123.ngrok.io/webhook
Monitor webhook delivery status and history:
Get webhook delivery logs
{
"status": true,
"logs": [
{
"id": 1,
"event": "order.created",
"status": "delivered",
"response_code": 200,
"response_time": 150,
"created_at": "2024-01-01T00:00:00.000000Z"
}
]
}
For additional support or questions about webhooks, please contact our development team.
Back to Documentation