
Dolibarr is an open-source ERP and CRM widely used by businesses to manage their commercial, financial, and administrative processes. One of its most powerful features is its REST API, which allows developers to automate tasks and integrate Dolibarr with other applications.
In this article, we will explore how to use Dolibarr’s REST API to automate common tasks such as managing customers, creating invoices, updating products, and synchronizing data with external services.
1. Introduction to Dolibarr’s REST API
Dolibarr’s REST API allows interaction with the system through HTTP requests. It is designed to provide secure access to Dolibarr’s data and functionalities, making integration with other tools easier.
Key Features of the REST API
- Management of customers and contacts (add, update, delete).
- Creation and updating of invoices and quotes.
- Management of products and services.
- Access to orders and payments.
- Reading and writing accounting data.
2. Enabling the REST API in Dolibarr
Before using the REST API, it must be enabled in Dolibarr, and access permissions must be configured.
Steps to Enable the API
- Log in as an administrator in Dolibarr.
- Go to "Home" → "Setup" → "Modules/Applications".
- Search for the "REST API" module and enable it.
- In the Configuration tab, generate an API key for each user or application that needs API access.
- Set up API permissions to restrict access to sensitive data.
Once the API is enabled, it can be accessed via the following URL:
3. Authentication and Security
Dolibarr uses a token-based authentication mechanism to secure API access.
Retrieve an Authentication Token
Authentication is done by sending a POST
request with the API credentials:
The response will contain an authentication token, which must be included in each API request using the DOLAPIKEY
header:
Securing the API
- Always use HTTPS to prevent data interception.
- Restrict access with specific user permissions.
- Regularly regenerate API keys.
- Monitor API access logs to detect suspicious activity.
4. Automating Customer Management
The REST API allows adding and modifying customers without using Dolibarr’s interface.
Create a New Customer
Here is an example POST
request to add a customer:
Dolibarr will return a unique ID for this customer, which can be used for further actions.
Update an Existing Customer
To modify a customer, use a PUT
request with the customer’s ID:
5. Automating Invoicing
Create an Invoice via the REST API
To generate an invoice, use the /invoices
endpoint:
Dolibarr will return the invoice ID, which can be used to send it via email or download it as a PDF.
6. Synchronizing Dolibarr with Other Tools
Dolibarr’s REST API can be used to synchronize data with external tools such as WooCommerce, Prestashop, Zapier, Google Sheets, Power BI, etc.
Example: Synchronization with an E-commerce Website
If you want to retrieve the list of products for a WooCommerce store, you can run the following request:
This command will return Dolibarr’s product information, which can be imported into WooCommerce using its own REST API.
7. Automating Reports and Analytics
Dolibarr’s API allows extracting data to generate custom reports.
Export Sales for the Current Month
To retrieve sales for the month:
This data can be integrated into Google Sheets, Power BI, or Excel for advanced analysis.
Conclusion
Dolibarr’s REST API is a powerful tool that allows automating many tasks and integrating Dolibarr with other systems. By enabling and securing the API properly, you can manage customers, create invoices, synchronize data with external platforms, and generate custom reports.
Whether for integration with an e-commerce website, a mobile application, or an external CRM, Dolibarr’s REST API facilitates automation and improves productivity.
If you want to go further, explore Dolibarr’s official documentation or use tools like Postman to test and optimize your API requests.