Dolibarr API Drupal module settings page screenshot

This project is not covered by Drupal’s security advisory policy.

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 the Swagger Explorer of the Dolibarr API module, 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 Dolibarr operationId (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 DOLAPIKEY token 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 the dolibarr_api channel, 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 -y

Configuration

  1. Create a Key at /admin/config/system/keys/add holding your Dolibarr
    DOLAPIKEY token (see Dolibarr user page to generate one, or use
    /admin/config/services/dolibarr_api/token to request one from a
    login/password pair).
  2. 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}

Examples :

  • 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.

AttachmentSize
dolibarr_api_get_token_screenshot.png46.06 KB

Project information

Releases