Dolibarr API
Full, typed PHP client for the Dolibarr REST API,
for Drupal. It exposes every resource of Dolibarr's Swagger specification
(agenda events, invoices, thirdparties, products, contracts, proposals,
supplier invoices/orders, tasks, projects, users, setup dictionaries...) as
one Drupal service per resource, with one typed PHP method per API operation.
The resource classes are generated from dolibarr_api_swagger.json, so
the whole API surface (330+ operations) is covered without hand-maintaining
thousands of lines of duplicated HTTP plumbing.
Features
- One service per Dolibarr API tag (
dolibarr_api.resource.invoices,dolibarr_api.resource.thirdparties, ...), each with typed methods named
after the DolibarroperationId(listInvoices(),retrieveInvoices($id),createThirdparties($data), ...). - A single facade service (
dolibarr_api) to reach any resource dynamically:\Drupal::service('dolibarr_api')->invoices->listInvoices(). - Centralized, secure authentication: the
DOLAPIKEYtoken is stored using
the Key module, never in plain
Drupal config. - Failures raise a
DolibarrApiException(with HTTP status + decoded
response body) and are logged to thedolibarr_apichannel, instead of
silently failing or depending on an active HTTP request (safe to use from
Drush, cron, queues...). - A regeneration script (
scripts/generate-resources.php) to keep the
resource classes in sync whenever Dolibarr's API evolves.
Installation
composer require drupal/dolibarr_api
drush en dolibarr_api key -yConfiguration
- Create a Key at
/admin/config/system/keys/addholding your DolibarrDOLAPIKEYtoken (see Dolibarr user page to generate one, or use/admin/config/services/dolibarr_api/tokento request one from a
login/password pair). - Go to
/admin/config/services/dolibarr_api, set your Dolibarr instance
URL and select the Key created above.
Usage
Inject a single resource (recommended)
public function __construct(
private readonly \Drupal\dolibarr_api\Resource\InvoicesResource $invoices,
) {}
public function myMethod(): void {
$invoices = $this->invoices->listInvoices(['thirdparty_ids' => 42]);
}Service ID: dolibarr_api.resource.{tag} (e.g. dolibarr_api.resource.invoices,dolibarr_api.resource.thirdparties, dolibarr_api.resource.products...).
Or use the facade for dynamic access
$dolibarrApi = \Drupal::service('dolibarr_api');
$invoices = $dolibarrApi->invoices->listInvoices([
'thirdparty_ids' => 42,
'limit' => 100,
'page' => 0
]);Error handling
use Drupal\dolibarr_api\Exception\DolibarrApiException;
try {
$invoices = $this->invoices->listInvoices();
}
catch (DolibarrApiException $e) {
// $e->getStatusCode(), $e->getResponseBody() are available.
\Drupal::logger('my_module')->error($e->getMessage());
}Contributing
Issues and merge requests are welcome. Please run phpcs (Drupal coding
standards, see phpcs.xml.dist) and the test suite before submitting.
Depends on
Dependencies of the latest stable release
- key Drupal core
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.