Interfaces from foreign systems toward Dolibarr: Difference between revisions

From Dolibarr ERP CRM Wiki
Jump to navigation Jump to search
mNo edit summary
(Add Chinese)
Tag: 2017 source edit
 
(20 intermediate revisions by 4 users not shown)
Line 1: Line 1:
<!-- BEGIN origin interlang links -->
<!-- You can edit this section but do NOT remove these comments
    Links below will be automatically replicated on translated pages by PolyglotBot -->
[[fr:Interfaces_Exterieur_vers_Dolibarr]]
[[es:Interfaces_del_Exterior_hacia_Dolibarr]]
[[zh:外部系统到Dolibarr的接口]]
<!-- END interlang links -->
{{TemplateDocDevEn}}
{{TemplateDocDevEn}}
There are 3 methods to allow an external application to insert data into Dolibarr. The 3 possible techniques are:
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:
 


= Insert data directly into database =
= Insert data directly into database =
Line 7: Line 18:
'''Advantages:''' Can be made in any language.
'''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.  
'''Disadvantage:''' This technique is highly discouraged. At the first upgrade of Dolibarr version, this method will not work and will need to be rewritten. Moreover, using this method, you override the business rules validations, which creates a risk of corrupting data. This method also needs to know the basis Dolibarr.


= Using PHP classes =
= 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:
It is possible to use business objects Dolibarr (xxx.class.php files). Each of these files provides a class of methods for:
* recovery of an entity (the fetch method)
* reading of an entity (the fetch method)
* insertion into database of an entity (the create method or insert)
* insertion into database of an entity (the create method or insert)
* updating an entity (the update method)
* updating an entity (the update method)
Line 21: Line 32:
'''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.
'''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.
'''Disadvantages:''' It is usable in PHP only. Your code must be stored on the same server as the Dolibarr files.


Here is an example for the creation of a third party (eg customer company):
See page [[Business Objects]].


<source lang="php">
= Web services =
// We declare the class we want to use
See [[Module Web Services REST|Module Web Services API REST]] and [[Module Web Services|Module Web Services API SOAP]].
include_once('/pathofdolibarrhtdocs/societe.class.php');


// We create an instance of object
The REST APIs are those used by the Automation tools nocode platforms.
$mycompany = new Societe($db);


// On set properties
= See also =
$mycompany->nom='Big Brother';
* [[Hooks system]]
$mycompany->client=1;
* [[Triggers]]
 
* [[Interfaces Dolibarr toward foreign systems]]
// 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);
</source>
 
Note: If we are inside an external script, you must add at the beginning of script, before the include of class we want to use:
<source lang="php">
include('/pathofdolibarrhtdocs/master.inc.php');
</source>
This will create objects $db, $lang and $user.
If we want that actions (create, update), are tagged with a particular user as the create/update user, you must do after the include of master.inc.php and before calling the create or update method
<source lang="php">
$user->fetch('loginuser');
</source>
 
= Web services =
Not yet available

Latest revision as of 06:58, 27 September 2023


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:


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 will not work and will need to be rewritten. Moreover, using this method, you override the business rules validations, 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 provides a class of methods for:

  • reading 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 the same server as the Dolibarr files.

See page Business Objects.

Web services

See Module Web Services API REST and Module Web Services API SOAP.

The REST APIs are those used by the Automation tools nocode platforms.

See also