Interfaces from foreign systems toward Dolibarr

From Dolibarr Wiki

Return to developer
documentation index

There are 3 methods to allow an external application to insert data into Dolibarr (For information on the other direction and allow Dolibarr to insert datas into external systems, see page Interfaces Dolibarr toward foreign systems).

To act on Dolibarr from external system, there is 3 possible solutions:


Contents

Insert data directly into database

This solution requires knowledge of the physical model and the allowed values of the fields. It is risky and should be rewritten if modified format based Dolibarr.

Advantages: Can be made in any language.

Disadvantage: This technique is highly discouraged. At the first upgrade of Dolibarr version, this method can not work and need to be rewritten. Moreover, using this method, you override the business rules validation, which creates a risk of corrupting data. This method also needs to know the basis Dolibarr.

Using PHP classes

It is possible to use business objects Dolibarr (xxx.class.php files). Each of these files has provided a class of methods for:

  • recovery of an entity (the fetch method)
  • insertion into database of an entity (the create method or insert)
  • updating an entity (the update method)
  • deletion of an entity (the delete method) if applicable to the object
  • various other methods specific to the entity manipulated.

This technique is better than first one.

Advantages: It offers the advantage of passing through layers of data validation business. The interface code should normally not be rewritten when upgrading version Dolibarr.

Disadvantages: It is usable in PHP only. Your code must be stored on same server than Dolibarr files.

Example for a third party

Here is an example for the creation of a third party (eg customer company):

If we make a new script or an external script, we must add at the beginning, before making anything else:

include('/pathofdolibarrhtdocs/master.inc.php');

This will initialize Dolibarr environment objects ($conf, $db, $lang and $user). If we want that actions (create, update) are tagged with a particular user as the create/update user, we must do after the include of master.inc.php and before calling any create or update method

$user->fetch(0,'loginuser');

Now we can make our business code.

// We declare the class we want to use
include_once('/pathofdolibarrhtdocs/societe.class.php');
 
// We create an instance of object to manipulate
$mycompany = new Societe($db);
 
// We set properties on object
$mycompany->nom='Big Brother';
$mycompany->client=1;
 
// If we want that creation is tagged as done by a particular user 'loginuser',
// you must uncomment this line to load all characteristics of this user.
// If we keep the comment, Dolibarr will use null if fields that should store the create or update user.
// $user->fetch('loginuser');
 
// On call method to create
$id=$mycompany->create($user);
 
// This is to read/load an already created object
$mycompany->fetch($id);
 
// To update object
$mycompany->update($user);

Other examples

You may find other example for manipulating Dolibarr objects (Create, Read, Update, Delete) into directory dev/samples of Dolibarr cvs snapshot.

Web services

See Module Web Services.

Personal tools
In other languages
FrenchSpanish