Table of Contents
-
Introduction
-
What Are Webhooks?
-
Why Use Webhooks in Dolibarr?
-
Understanding Dolibarr’s Webhook Capabilities
-
Common Use Cases for Webhook Automation
-
Enabling Webhooks in Dolibarr
-
Creating Webhook Endpoints
-
Securing Webhook Communications
-
Working with Event Triggers in Dolibarr
-
Receiving Webhooks in a Middleware
-
Example: Automating Invoice Processing
-
Example: Real-Time Order Notifications
-
Using Webhooks for CRM Integration
-
Connecting Dolibarr with Slack, Discord, or Email Alerts
-
Advanced Workflows: Approval Chains and Task Creation
-
Logging and Monitoring Webhook Activity
-
Testing Webhooks Effectively
-
Troubleshooting Webhook Issues
-
Best Practices for Scalable Automation
-
Conclusion
1. Introduction
Modern business applications thrive on automation. In Dolibarr ERP/CRM, automating repetitive tasks and triggering workflows based on system events is possible using webhooks. This guide explores how to configure, secure, and use webhooks within Dolibarr to streamline operations and integrate with external systems.
2. What Are Webhooks?
Webhooks are user-defined HTTP callbacks triggered by events. When a specified action occurs (e.g., a new invoice is validated), Dolibarr sends a POST request to a predefined URL, usually carrying a payload of data about the event.
Webhooks are often used for real-time notifications and automation between systems.
3. Why Use Webhooks in Dolibarr?
Benefits include:
-
Automating notifications
-
Real-time integrations
-
Reducing the need for polling APIs
-
Enabling event-driven systems
Examples:
-
Alerting an admin when a new order is placed
-
Automatically syncing data to external CRMs or apps
-
Triggering invoice validation workflows
4. Understanding Dolibarr’s Webhook Capabilities
Dolibarr includes basic webhook support via its trigger system. Developers can:
-
Hook into predefined actions
-
Use
interface_99_modXXX_YYY.class.php
classes -
Customize behavior for modules like orders, invoices, products, etc.
Dolibarr does not offer a full UI for webhooks but provides programmatic access and customization.
5. Common Use Cases for Webhook Automation
-
Send invoice details to external billing services
-
Notify warehouse staff of new shipments
-
Integrate with Slack or Microsoft Teams
-
Push CRM lead data to third-party platforms
-
Trigger external scripts for PDF generation or reporting
6. Enabling Webhooks in Dolibarr
To activate webhook logic:
-
Ensure developer mode is on in
conf.php
-
Navigate to
/htdocs/core/triggers/
-
Create or customize a trigger file
Example file: interface_99_modWebhook_Mytrigger.class.php
7. Creating Webhook Endpoints
Endpoints are servers that listen for webhook calls. You can build one using:
-
Node.js (Express)
-
Python (Flask/FastAPI)
-
PHP
Basic example in PHP:
$input = file_get_contents('php://input');
$data = json_decode($input, true);
file_put_contents('log.txt', print_r($data, true));
Ensure your endpoint is publicly accessible and supports HTTPS.
8. Securing Webhook Communications
To protect your system:
-
Use HTTPS to encrypt payloads
-
Include a shared secret in the header
-
Validate payload source IP
-
Log all webhook activity
Implement signature validation to avoid spoofed calls.
9. Working with Event Triggers in Dolibarr
Dolibarr uses internal events like:
-
BILL_VALIDATE
-
ORDER_CREATE
-
PRODUCT_CREATE
In your custom trigger, use run_trigger()
to catch events and send a POST to your endpoint:
if ($action == 'ORDER_VALIDATE') {
$payload = json_encode($object);
file_get_contents('https://your-endpoint.com/hook?payload=' . $payload);
}
10. Receiving Webhooks in a Middleware
Middleware acts as a relay between Dolibarr and other services. Example:
-
Receive data from Dolibarr
-
Transform or filter it
-
Push it to a third-party API (e.g., Salesforce, Notion)
Middleware platforms: Zapier, Make.com, n8n, or a custom server.
11. Example: Automating Invoice Processing
Trigger: BILL_VALIDATE
Workflow:
-
User validates invoice
-
Webhook sends data to invoice management tool
-
Tool replies with confirmation or failure
-
Dolibarr logs the response and updates status
This reduces manual syncing with external accounting tools.
12. Example: Real-Time Order Notifications
Trigger: ORDER_CREATE
Use case:
-
Send message to Slack when a new order is placed
Workflow:
-
Webhook sends JSON to middleware
-
Middleware formats message
-
Slack webhook posts message to sales channel
13. Using Webhooks for CRM Integration
Trigger: THIRDPARTY_CREATE
, CONTACT_CREATE
Use case:
-
Push new clients to external CRM
The webhook sends payloads to your CRM’s API, creating leads or customer profiles automatically.
14. Connecting Dolibarr with Slack, Discord, or Email Alerts
Use Zapier or a custom relay:
-
Format payload to readable message
-
POST to Slack/Discord via webhook URL
-
Send email via SMTP with triggered content
Add emoji reactions or timestamps for clarity.
15. Advanced Workflows: Approval Chains and Task Creation
Use webhooks to:
-
Create approval tasks in project management tools (e.g., Asana, Trello)
-
Notify supervisors when thresholds are reached (e.g., invoice > $10,000)
Workflow:
-
Trigger fires
-
Middleware checks conditions
-
If condition met, task or alert is created
16. Logging and Monitoring Webhook Activity
Log webhook actions:
-
File logs in
/var/logs/
-
Store metadata in Dolibarr extra fields
-
Use external services like Loggly or Datadog for monitoring
Log entries should include timestamps, response codes, and any errors.
17. Testing Webhooks Effectively
Use tools:
-
RequestBin or Webhook.site for inspecting payloads
-
Postman to simulate Dolibarr webhook calls
-
ngrok for testing locally behind firewalls
Simulate each event to verify flow before production use.
18. Troubleshooting Webhook Issues
Common problems:
-
HTTP 500 from endpoint (check error logs)
-
Invalid payload structure (compare schemas)
-
Timeouts (optimize processing time)
Always retry failed requests if they are critical.
19. Best Practices for Scalable Automation
-
Use queues (e.g., RabbitMQ) to process events asynchronously
-
Batch webhook events if volumes are high
-
Apply exponential backoff for retries
-
Separate critical and non-critical workflows
Document your webhooks and provide fallback mechanisms.
20. Conclusion
Webhooks enable real-time automation and powerful integrations in Dolibarr. By setting up secure endpoints, designing intelligent workflows, and monitoring activity, you can eliminate redundant tasks and boost your system’s responsiveness. Whether for internal processes or third-party communication, webhooks make your Dolibarr installation truly dynamic.