<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.dolibarr.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jonbendtsen</id>
	<title>Dolibarr ERP CRM Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.dolibarr.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jonbendtsen"/>
	<link rel="alternate" type="text/html" href="https://wiki.dolibarr.org/index.php/Special:Contributions/Jonbendtsen"/>
	<updated>2026-11-22T13:15:23Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.17</generator>
	<entry>
		<id>https://wiki.dolibarr.org/index.php?title=Security_information&amp;diff=66084</id>
		<title>Security information</title>
		<link rel="alternate" type="text/html" href="https://wiki.dolibarr.org/index.php?title=Security_information&amp;diff=66084"/>
		<updated>2026-05-04T18:19:28Z</updated>

		<summary type="html">&lt;p&gt;Jonbendtsen: Added a note about API explorer not working with AcceptPathInfo off&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!-- BEGIN origin interlang links --&amp;gt;&lt;br /&gt;
&amp;lt;!-- You can edit this section but do NOT remove these comments&lt;br /&gt;
     Links below will be automatically replicated on translated pages by PolyglotBot --&amp;gt;&lt;br /&gt;
[[fr:Informations_sécurité]]&lt;br /&gt;
[[es:Información_de_seguridad]]&lt;br /&gt;
[[zh:安全信息]]&lt;br /&gt;
&amp;lt;!-- END interlang links --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Admin_en]]&lt;br /&gt;
{{TemplateDocUser}}&lt;br /&gt;
{{TemplateDocDevEn}}&lt;br /&gt;
&lt;br /&gt;
This page is an entry point to the various information relating to Dolibarr ERP CRM in relation to security.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=[[File:securite.png]] Security Alerts=&lt;br /&gt;
&lt;br /&gt;
To list or receive all official alerts about known security vulnerabilities (aggregation of official published CVE, Private Vulnerability Disclosure, project issues) on Dolibarr project you can:&lt;br /&gt;
&lt;br /&gt;
*look at the section &amp;quot;&#039;&#039;&#039;Security alerts&#039;&#039;&#039;&amp;quot; available on this page https://cti.dolibarr.org,&lt;br /&gt;
*or subscribe to the RSS feed at https://cti.dolibarr.org/index-security.rss if you need to receive or read alert in real time on your smartphone (for example with the Android application [https://f-droid.org/packages/com.nononsenseapps.feeder/ Feeder]).&lt;br /&gt;
&lt;br /&gt;
*If you want to also receive security alerts not yet known by the project team, and published in the international CVE database, you can subscribe to a CVE alert service, for example https://opencve.io).&lt;br /&gt;
&lt;br /&gt;
=[[File:art.png]] Security Features=&lt;br /&gt;
Dolibarr implements several security features to match best practices rules related to security.&lt;br /&gt;
 &lt;br /&gt;
This is a list of main security features you can find&amp;lt;span&amp;gt; &amp;lt;/span&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Encryption==&lt;br /&gt;
&lt;br /&gt;
*Passwords or security keys data are encrypted in database &amp;lt;sup&amp;gt;[*7]&amp;lt;/sup&amp;gt; &amp;lt;sup&amp;gt;[*8]&amp;lt;/sup&amp;gt;.&lt;br /&gt;
*The database technical password can be obfuscated into the [[Configuration_file|Dolibarr configuration file]] (conf.php) &amp;lt;sup&amp;gt;[*8]&amp;lt;/sup&amp;gt;.&lt;br /&gt;
*Possibility to force HTTPS &amp;lt;sup&amp;gt;[*9]&amp;lt;/sup&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
//conf/conf.php file&lt;br /&gt;
//example of $dolibarr_main_force_https  configuration&lt;br /&gt;
$dolibarr_main_force_https = &#039;1&#039;;//to force https&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width:100%;&amp;quot;&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; |Values&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; |Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;width:50%;&amp;quot; |&lt;br /&gt;
0&lt;br /&gt;
| style=&amp;quot;width:50%;&amp;quot; |&lt;br /&gt;
No forced redirect&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;width:50%;&amp;quot; |&lt;br /&gt;
1&lt;br /&gt;
| style=&amp;quot;width:50%;&amp;quot; |&lt;br /&gt;
Force redirect to https, until SCRIPT_URI start with https into response&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;width:50%;&amp;quot; |&lt;br /&gt;
2&lt;br /&gt;
| style=&amp;quot;width:50%;&amp;quot; |&lt;br /&gt;
Force redirect to https, until SERVER[&amp;quot;HTTPS&amp;quot;] is &#039;on&#039; into response&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;width:50%;&amp;quot; |&lt;br /&gt;
https://mydomain&lt;br /&gt;
| style=&amp;quot;width:50%;&amp;quot; |&lt;br /&gt;
Force redirect to the https domain name mydomain (recommended method)&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Features Anti Hacks and cracks==&lt;br /&gt;
&lt;br /&gt;
*Works with PHP register_globals on or off (off highly recommended) &amp;lt;sup&amp;gt;[*2]&amp;lt;/sup&amp;gt;.&lt;br /&gt;
*Works with PHP safe_mode on or off (on recommended) &amp;lt;sup&amp;gt;[*3]&amp;lt;/sup&amp;gt;.&lt;br /&gt;
*Production mode to disable any technical information leakage like debug, error stacktrace, version informations (See [[Configuration_file|configuration file]]) &amp;lt;sup&amp;gt;[*6]&amp;lt;/sup&amp;gt;.&lt;br /&gt;
*WAF: Protection against SQL injection. Protected by an Internal WAF, and unit test to check database good practice for escapement. &amp;lt;sup&amp;gt;[*2]&amp;lt;/sup&amp;gt;.&lt;br /&gt;
*WAF: Protection against XSS injection (Cross Site Scripting). Protected by an internal WAF and web page headers. &amp;lt;sup&amp;gt;[*1]&amp;lt;/sup&amp;gt;.&lt;br /&gt;
*Protection against SSRF. All access to an URL uses the getURLContent() method into core/lib/geturl.lib.php that brings this protection.&lt;br /&gt;
*Protection against CSRF (Cross Site Request Forgery). Protected by an internal WAF and a token system (with several level of renewal policies, by session or by page). &amp;lt;sup&amp;gt;[*5]&amp;lt;/sup&amp;gt;.&lt;br /&gt;
*Application features for quotas (upload limits, file extensions, file sizes, etc.)&lt;br /&gt;
&lt;br /&gt;
Note that it is also recommended to protect your web server by disabling the Apache option&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ini&amp;quot;&amp;gt;&lt;br /&gt;
AcceptPathInfo Off&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; - Note that the API explorer does not work with &amp;lt;syntaxhighlight lang=&amp;quot;ini&amp;quot;&amp;gt;&lt;br /&gt;
AcceptPathInfo Off&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Pages and files access==&lt;br /&gt;
&lt;br /&gt;
*Pages and contents are protected by centralized entry code to check permissions (granted on groups or users for each functional module) &amp;lt;sup&amp;gt;[*4]&amp;lt;/sup&amp;gt; &amp;lt;sup&amp;gt;[*10]&amp;lt;/sup&amp;gt;.&lt;br /&gt;
*Files saved by Dolibarr are stored in a different root directory than web application (so they can&#039;t be downloaded without passing by the Dolibarr wrapper) &amp;lt;sup&amp;gt;[*3]&amp;lt;/sup&amp;gt; &amp;lt;sup&amp;gt;[*10]&amp;lt;/sup&amp;gt;. Note: You must check that you did not choose the &amp;quot;&#039;&#039;&#039;document&#039;&#039;&#039;&amp;quot; directory (for upload files) to be in same directory neither in a sub-directory than the &amp;quot;&#039;&#039;&#039;htdocs&#039;&#039;&#039;&amp;quot; directory. You web virtual host must point to the htdocs directory only (and this directoy can/should be in read only mode). So any uploaded file (stored into the document directory) can&#039;t be download without using the wrapper page.&lt;br /&gt;
*Sanitization of directory and file names (internal functions dol_sanitizeFilename() and dol_sanitizePathname().&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Login protection==&lt;br /&gt;
&lt;br /&gt;
*Delay anti brute force cracking on login page &amp;lt;sup&amp;gt;[*7]&amp;lt;/sup&amp;gt;. Currently this delay is fixed (May be exponential with tries in a future version).&lt;br /&gt;
*Option for graphical code (CAPTCHA) against robots on login page &amp;lt;sup&amp;gt;[*7]&amp;lt;/sup&amp;gt;.&lt;br /&gt;
*Restrict access to backoffice for some IP only &amp;lt;sup&amp;gt;[*7]&amp;lt;/sup&amp;gt;.&lt;br /&gt;
*No passwords in logs, even in technical logs &amp;lt;sup&amp;gt;[*7]&amp;lt;/sup&amp;gt;.&lt;br /&gt;
*Internal logger to save permanently all Dolibarr events about user&#039;s administration and successful or failed logins or administration events (like user or group or permission changes).&lt;br /&gt;
*Can output a log record into a log file (module Debug Log must be enabled with at least level 5-LOG_NOTICE on production server, higher on development server) after success or failed login attempt so you can add a fail2ban rule to lock brute force cracking. You can check record with syntax&amp;lt;span&amp;gt; &amp;lt;/span&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;YYYY-MM-DD HH:MM:SS (ERROR|NOTICE|INFO|DEBUG)    IP functions_dolibarr::check_user_password_.* Authentication KO&amp;quot;&lt;br /&gt;
A list of fail2ban rules to add to your server is provided on chapter &#039;&#039;&#039;DOS and Brute force rate Mitigation&#039;&#039;&#039; later.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Viruses==&lt;br /&gt;
&lt;br /&gt;
*Possibility to run an external anti-virus on every uploaded files &amp;lt;sup&amp;gt;[*3]&amp;lt;/sup&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Security Information Center==&lt;br /&gt;
&lt;br /&gt;
*From version 14, you will find into menu Home - Admin tools - Security, a security information center that report you all recommandations done and to do related to your installation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==A CTI for security==&lt;br /&gt;
&lt;br /&gt;
A continuous integration platform run Security unit tests and static code analysis on each modification of code.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==A footprint for each version==&lt;br /&gt;
&lt;br /&gt;
Our release process bring each version with a footprint file (also available online) to validate all files of your local installation and detect any change on any file with the integrated tool available in menu Home - Administration - Security.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==DOS and Brute force rate Mitigation==&lt;br /&gt;
&lt;br /&gt;
*Embedded AntiDOS features with quota on public action per IP.&lt;br /&gt;
&lt;br /&gt;
*The project provide also examples of some fail2ban rules to block brute force attempts or abusive access on login page, password forgotten page and on any public pages. See https://github.com/Dolibarr/dolibarr/tree/develop/dev/setup/fail2ban&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==OpenSourceSSF==&lt;br /&gt;
&lt;br /&gt;
Dolibarr conforms to the Best Practices defined by the OpenSourceSSF: https://bestpractices.coreinfrastructure.org/projects/5521&lt;br /&gt;
&lt;br /&gt;
=[[File:art.png]] Report a security vulnerability=&lt;br /&gt;
&lt;br /&gt;
To report a vulnerability, see the file: https://github.com/Dolibarr/dolibarr/blob/develop/SECURITY.md&lt;br /&gt;
&lt;br /&gt;
In most cases, security reports are processed in few days.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=[[File:art.png]] Bug Bounty and VDP Campaigns=&lt;br /&gt;
Bug bounty campaigns are regularly conducted by the project and funded by the Dolibarr Association. These campaigns are private VDP (Vulnerability Disclosure Programs) managed by specialized partners (Examples: https://yogosha.com, https://huntr.com/).&lt;br /&gt;
&lt;br /&gt;
Fixes from these campaigns are published within 15 days, as with any other public vulnerability report (this is the timeframe observed by the community project; contact a Dolibarr Preferred Partner if you require a longer contractual timeframe).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;sup&amp;gt;(*X)&amp;lt;/sup&amp;gt; This solution is part of protection used to solve vulnerabilities classified by the [http://www.owasp.org/index.php/Top_10_2007 OWASP Top Ten 2007] at range number X. Value for position X may have been changed since.&lt;/div&gt;</summary>
		<author><name>Jonbendtsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.dolibarr.org/index.php?title=Authentication,_SSO_and_SSL&amp;diff=64605</id>
		<title>Authentication, SSO and SSL</title>
		<link rel="alternate" type="text/html" href="https://wiki.dolibarr.org/index.php?title=Authentication,_SSO_and_SSL&amp;diff=64605"/>
		<updated>2025-10-29T18:43:38Z</updated>

		<summary type="html">&lt;p&gt;Jonbendtsen: /* Composing MAIN_AUTHENTICATION_OPENID_URL */ removing a single confusing word&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Core]]&lt;br /&gt;
&lt;br /&gt;
=Authentication setup in Dolibarr=&lt;br /&gt;
&lt;br /&gt;
There is different solutions to be authenticated with Dolibarr. You can set the selected authentication method into the file &#039;&#039;&#039;htdocs/conf/conf.php&#039;&#039;&#039; in the parameter &#039;&#039;&#039;$dolibarr_authentication_mode&#039;&#039;&#039;. This is a list of available values:&lt;br /&gt;
&lt;br /&gt;
*dolibarr&lt;br /&gt;
*http&lt;br /&gt;
*ldap&lt;br /&gt;
*forceuser&lt;br /&gt;
*googleoauth (for Google OAuth 2 authentication, Dolibarr 18+)...&lt;br /&gt;
&lt;br /&gt;
You can combine several methods (some combinations are however technically not compatible). If you use several method (separated by a coma), you will try to authenticate using the first method and if it fails, the next method will be used. For example, if you set &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$dolibarr_authentication_mode=&amp;quot;ldap,dolibarr&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
the system will try to authenticate using the LDAP database and if it fails it will try to login using the internal Dolibarr login/password&lt;br /&gt;
&lt;br /&gt;
Each authentication mode may have complementary parameters (also into htdocs/conf/conf.php file) to have them working.&lt;br /&gt;
Let&#039;s have a look at each available method:&lt;br /&gt;
&lt;br /&gt;
=Description of available authentication modes=&lt;br /&gt;
&lt;br /&gt;
==Mode dolibarr==&lt;br /&gt;
With this method, the login and pass you entered on login page will be compared to the login and the hashed password saved into the Dolibarr database ([[Table llx_user]]).&lt;br /&gt;
&lt;br /&gt;
==Mode http==&lt;br /&gt;
You can set the authentication mode to &amp;quot;http&amp;quot; if your Dolibarr web application is protected by an Apache http basic authentication form. The login/pass are stored into the file used by the HTTP Basic system to store passwords (it is often a file called &#039;&#039;&#039;.htpasswd&#039;&#039;&#039; if you used the &#039;&#039;&#039;mod_auth_basic&#039;&#039;&#039; + &#039;&#039;&#039;mod_authn_file&#039;&#039;&#039; plugin of Apache).&lt;br /&gt;
&lt;br /&gt;
This is an exemple of setup for Apache to protect your instance to be accessed using the HTTP Basic authentication (uncomment the section under line &amp;quot;# To restrict access by a HTTP basic auth&amp;quot; in this example)&lt;br /&gt;
&lt;br /&gt;
https://github.com/Dolibarr/dolibarr/blob/develop/dev/setup/apache/virtualhost&lt;br /&gt;
&lt;br /&gt;
Note that the user must also exists as a existing user into the Dolibarr user database. Also the date of validity of this user must be valid.&lt;br /&gt;
&lt;br /&gt;
==Mode ldap==&lt;br /&gt;
If you set the authentication mode to LDAP, the test of the validity of your login and password are done using a LDAP database.&lt;br /&gt;
&lt;br /&gt;
The parameters to define where is your LDAP must be defined into the variable  &#039;&#039;&#039;$dolibarr_main_auth_ldap_...&#039;&#039;&#039; (Fo security purpose, the parameters defined into the LDAP module of Dolibarr are used only by the pages of the application that need LDAP access, but for the authentication, only variables defined into the conf/conf.php file are used)&lt;br /&gt;
&lt;br /&gt;
See the file https://github.com/Dolibarr/dolibarr/blob/develop/htdocs/conf/conf.php.example for the list of $dolibarr_main_auth_ldap_... variables.&lt;br /&gt;
&lt;br /&gt;
Note that the user must also exists as an existing user into the Dolibarr user database. Also the date of validity of this user must be valid.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mode forceuser==&lt;br /&gt;
When this method is used, there is no need to enter a login or password. No login page is shown. The user will be automatically set to the one defined into the variable &#039;&#039;&#039;$dolibarr_auto_user&#039;&#039;&#039; saved into  &#039;&#039;&#039;htdocs/conf/conf.php&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This mode is used only on development platforms. For example on an instance used to make demo or automated tests.&lt;br /&gt;
&lt;br /&gt;
Note that the user must also exists as a existing user into the Dolibarr user database. Also the date of validity of this user must be valid.&lt;br /&gt;
&lt;br /&gt;
==Mode googleoauth==&lt;br /&gt;
This code is to use the Google OAuth 2 authentication. It is available with version 18+.&lt;br /&gt;
&lt;br /&gt;
*First enable the [[Module OAuth]] on Dolibarr.&lt;br /&gt;
*Into the setup of the module, you must create an OAuth entry for provider Google and label &amp;quot;&#039;&#039;&#039;Login&#039;&#039;&#039;&amp;quot; (no other label will works). You will find a value for a &#039;&#039;&#039;Redirect URI&#039;&#039;&#039; that you must use in the next step.&lt;br /&gt;
*Go on Google console https://console.cloud.google.com/ - Menu API and services - Credentials, and create an &#039;&#039;&#039;OAuth ID client&#039;&#039;&#039;. You must use the URL found at previous step as &#039;&#039;&#039;Authorized redirect URIs&#039;&#039;&#039;.&lt;br /&gt;
*Go back to the Dolibarr OAuth setup page to enter the &#039;&#039;&#039;client ID&#039;&#039;&#039; and &#039;&#039;&#039;secret ID&#039;&#039;&#039; of the OAuth entry you have created. Choose the scope/permissions &amp;quot;&#039;&#039;&#039;openid&#039;&#039;&#039;&amp;quot; and &amp;quot;&#039;&#039;&#039;email&#039;&#039;&#039;&amp;quot;.&lt;br /&gt;
*Edit the file conf/conf.php and set $dolibarr_main_authentication to &amp;quot;googleoauth&amp;quot; or &amp;quot;dolibarr,googleoauth&amp;quot; to allow both authentication with Dolibarr login/pass and with Google OAuth2&lt;br /&gt;
&lt;br /&gt;
Now try to login. You must enter your Google account and you will be able to login without password if and only if a user exists into the Dolibarr database with the same email address than the one used to login to Google.&lt;br /&gt;
&lt;br /&gt;
==Mode openid==&lt;br /&gt;
The method &amp;quot;openid&amp;quot; is an old method for using openID.&lt;br /&gt;
Try to use instead the next method &amp;quot;openid_connect&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==Mode openid_connect==&lt;br /&gt;
&lt;br /&gt;
===OpenID Connect using the native method===&lt;br /&gt;
This is a new method available with Dolibarr v18 to connect using OpenID Connect.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====In the Dolibarr conf file====&lt;br /&gt;
&lt;br /&gt;
#Configure the authentication methods in &amp;lt;code&amp;gt;conf.php&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;/var/www/html/conf/conf.php&amp;lt;/code&amp;gt;) and add &amp;lt;code&amp;gt;openid_connect&amp;lt;/code&amp;gt;. For e.g.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$dolibarr_main_authentication=&#039;openid_connect,dolibarr&#039;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Dolibarr application setup====&lt;br /&gt;
&lt;br /&gt;
Then you must set parameters and options of your openid connect service. In development branch commit 4c84650e39d5ce97c38f55e06ab0d47fe5df0435 you can not seem to search for this openid module, but follow this path: Top menu Home, left menu Security, tab called &#039;Configuration of the OpenID Connect module&#039;. From v21, you can enable the module OpenIDConnect to edit them. From v18 to v20, you must edit them from menu &#039;&#039;&#039;Home - Setup - Other&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Name&lt;br /&gt;
!Example&lt;br /&gt;
!Comment&lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;MAIN_AUTHENTICATION_OIDC_CLIENT_ID&amp;lt;/code&amp;gt;&lt;br /&gt;
|&amp;lt;code&amp;gt;My-Super-Awesome-Client-ID-1234&amp;lt;/code&amp;gt;&lt;br /&gt;
|OpenID Connect Client ID&lt;br /&gt;
|Application client ID&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;MAIN_AUTHENTICATION_OIDC_CLIENT_SECRET&amp;lt;/code&amp;gt;&lt;br /&gt;
|&amp;lt;code&amp;gt;My-Very-Hidden-Client-Secret-1234&amp;lt;/code&amp;gt;&lt;br /&gt;
|OpenID Connect Client Secret&lt;br /&gt;
|Application client secret&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;MAIN_AUTHENTICATION_OIDC_AUTHORIZE_URL&amp;lt;/code&amp;gt;&lt;br /&gt;
|&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;https://tenant.us.auth0.com/oauth/authorize&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
|OpenID Authorize URL&lt;br /&gt;
|&amp;lt;code&amp;gt;/authorize&amp;lt;/code&amp;gt; endpoint&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;MAIN_AUTHENTICATION_OIDC_TOKEN_URL&amp;lt;/code&amp;gt;&lt;br /&gt;
|&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;https://tenant.us.auth0.com/oauth/token&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
|OpenID Connect token URL&lt;br /&gt;
|&amp;lt;code&amp;gt;/token&amp;lt;/code&amp;gt; endpoint&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;MAIN_AUTHENTICATION_OIDC_USERINFO_URL&amp;lt;/code&amp;gt;&lt;br /&gt;
|&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;https://tenant.us.auth0.com/userinfo&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
|OpenID Connect userinfo URL&lt;br /&gt;
|&amp;lt;code&amp;gt;/userinfo&amp;lt;/code&amp;gt; endpoint&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;MAIN_AUTHENTICATION_OIDC_REDIRECT_URL&amp;lt;/code&amp;gt;&lt;br /&gt;
|&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;https://dolibarr.domain.com/?openid_mode=true&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
|OpenID Connect redirect URL&lt;br /&gt;
|Dolibarr URL followed by &amp;lt;code&amp;gt;/?openid_mode=true&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;MAIN_AUTHENTICATION_OIDC_LOGIN_CLAIM&amp;lt;/code&amp;gt;&lt;br /&gt;
|&amp;lt;code&amp;gt;email&amp;lt;/code&amp;gt;&lt;br /&gt;
|OpenID Connect login claim&lt;br /&gt;
|OpenID Connect claim matching the Dolibarr user login. If not set or empty, defaults to &amp;lt;code&amp;gt;email&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;MAIN_LOGOUT_GOTO_URL&amp;lt;/code&amp;gt;&lt;br /&gt;
|See later&lt;br /&gt;
|Identity Provider logout URL&lt;br /&gt;
|Composed IdP logout URL&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Source page https://github.com/Dolibarr/dolibarr/issues/22740.&lt;br /&gt;
&lt;br /&gt;
====Composing &amp;lt;code&amp;gt;MAIN_AUTHENTICATION_OPENID_URL&amp;lt;/code&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
The MAIN_AUTHENTICATION_OPENID_URL will be generated (but if you prefer, you can set it manually from Home - Setup - Other) to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
MAIN_AUTHENTICATION_OIDC_AUTHORIZE_URL?client_id=MAIN_AUTHENTICATION_OIDC_CLIENT_ID&amp;amp;redirect_uri=mydolibarr/core/modules/openid_connect/callback.php&amp;amp;scope=MAIN_AUTHENTICATION_OIDC_SCOPES&amp;amp;response_type=code&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is the main OpenID Connect authentication URL, which allows the user to log in and then be redirected back to Dolibarr. It makes use of some already existing OpenID 2.0 features.&lt;br /&gt;
&lt;br /&gt;
#Retrieve the &amp;lt;code&amp;gt;/authorize&amp;lt;/code&amp;gt; endpoint of your OpenID server. The value depends on the used Identity Provider.  E.g.: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;https://tenant.us.auth0.com/authorize&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
#Build the URL parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Param name&lt;br /&gt;
!Description&lt;br /&gt;
!Example&lt;br /&gt;
|-&lt;br /&gt;
|client_id&lt;br /&gt;
|Application client ID&lt;br /&gt;
|&amp;lt;code&amp;gt;My-Super-Awesome-Client-ID-1234&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|redirect_uri&lt;br /&gt;
|Dolibarr URL followed by &amp;lt;code&amp;gt;/?openid_mode=true&amp;lt;/code&amp;gt;, then URL encoded. Must be authorized as callback URL&lt;br /&gt;
|Before URL encoding: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;https://dolibarr.domain.com/?openid_mode=true&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; - After URL encoding: &amp;lt;code&amp;gt;https%3A%2F%2Fdolibarr.domain.com%2F%3Fopenid_mode%3Dtrue&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|scope&lt;br /&gt;
|OpenID scope of required user info&lt;br /&gt;
|&amp;lt;code&amp;gt;openid profile email&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|response_type&lt;br /&gt;
|OAuth flow name, here we use &amp;lt;code&amp;gt;code&amp;lt;/code&amp;gt; for the Authorization Code flow&lt;br /&gt;
|&amp;lt;code&amp;gt;code&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|state&lt;br /&gt;
|A number&lt;br /&gt;
|1234568&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The final MAIN_AUTHENTICATION_OPENID_URL content should be like:  &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;https://tenant.us.auth0.com/authorize?client_id=My-Super-Awesome-Client-ID-1234&amp;amp;redirect_uri=https%3A%2F%2Fdolibarr.domain.com%2F%3Fopenid_mode%3Dtrue&amp;amp;scope=openid&amp;lt;/nowiki&amp;gt; profile email&amp;amp;response_type=code&amp;amp;state=anumber&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Composing &amp;lt;code&amp;gt;MAIN_LOGOUT_GOTO_URL&amp;lt;/code&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
#Retrieve the &amp;lt;code&amp;gt;/logout&amp;lt;/code&amp;gt; endpoint. The value depends on the used Identity Provider.  E.g.: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;https://tenant.us.auth0.com/v2/logout&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;Build the URL parameters&lt;br /&gt;
#Build the URL parameters&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Param name&lt;br /&gt;
!Description&lt;br /&gt;
!Example&lt;br /&gt;
|-&lt;br /&gt;
|client_id&lt;br /&gt;
|Application client ID&lt;br /&gt;
|&amp;lt;code&amp;gt;My-Super-Awesome-Client-ID-1234&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|returnTo&lt;br /&gt;
|URL to be redirected to after logout. Use Dolibarr URL. Must be authorized as logout URL&lt;br /&gt;
|&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;https://dolibar.domain.com&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
#The final MAIN_LOGOUT_GOTO_URL content should be like:  &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;https://tenant.us.auth0.com/v2/logout?client_id=My-Super-Awesome-Client-ID-1234&amp;amp;returnTo=https://dolibar.domain.com&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===OpenID Connect using OpenID and the HTTP Basic of Apache===&lt;br /&gt;
If you need to connect using OpenID Connect without using the native method (for example for Dolibarr &amp;lt; 18), you can also do it using the following solution:&lt;br /&gt;
&lt;br /&gt;
The idea is to use two elements:&lt;br /&gt;
&lt;br /&gt;
*The auth_openidc plugin for Apache&lt;br /&gt;
*Dolibarr HTTP authentication.&lt;br /&gt;
&lt;br /&gt;
The procedure will therefore require Dolibarr installed with Apache and the apache module https://github.com/zmartzone/mod_auth_openidc. The latter is often directly available on Linux via a package manager command.&lt;br /&gt;
&lt;br /&gt;
The second part will therefore be to configure this apache module in order to authenticate users with the OpenID Connect protocol. In the general case, you will only need the metadata URL.&lt;br /&gt;
Here is an example apache configuration for OpenID with AzureAD:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ini&amp;quot;&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
    OIDCProviderMetadataURL https://login.microsoftonline.com/your-tenant-id/v2.0/.well-known/openid-configuration&lt;br /&gt;
    OIDCClientID youropenidclient&lt;br /&gt;
    OIDCClientSecret yoursecret&lt;br /&gt;
    OIDCCryptoPassphrase randomstring&lt;br /&gt;
    OIDCRedirectURI https://mydolibarr.example.com/sso_redirect&lt;br /&gt;
    OIDCScope &amp;quot;openid email profile&amp;quot;&lt;br /&gt;
    OIDCRemoteUserClaim email ^(.*)@&lt;br /&gt;
&lt;br /&gt;
    # Disable openid-connect if using DoliDroid&lt;br /&gt;
    SetEnvIf User-Agent DoliDroid no-auth&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;Directory /home/.../htdocs&amp;gt;&lt;br /&gt;
        # Docroot&lt;br /&gt;
        AuthType openid-connect&lt;br /&gt;
        Require valid-user&lt;br /&gt;
        Require env no-auth&lt;br /&gt;
    &amp;lt;/Directory&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    # Disallow openid-connect on some public pages or services&lt;br /&gt;
    # Leaving /public and /api, /dav, .well_known but also wrappers for document, viewimage and public json/img accessible to everyone&lt;br /&gt;
    &amp;lt;Directory /home/admin/wwwroot/dolibarr/htdocs/public/&amp;gt;&lt;br /&gt;
        AuthType None&lt;br /&gt;
        Satisfy any&lt;br /&gt;
        Require all granted&lt;br /&gt;
    &amp;lt;/Directory&amp;gt;&lt;br /&gt;
    &amp;lt;Directory /home/admin/wwwroot/dolibarr/htdocs/api/&amp;gt;&lt;br /&gt;
        AuthType None&lt;br /&gt;
        Satisfy any&lt;br /&gt;
        Require all granted&lt;br /&gt;
    &amp;lt;/Directory&amp;gt;&lt;br /&gt;
    &amp;lt;Directory /home/admin/wwwroot/dolibarr/htdocs/dav/&amp;gt;&lt;br /&gt;
        AuthType None&lt;br /&gt;
        Satisfy any&lt;br /&gt;
        Require all granted&lt;br /&gt;
    &amp;lt;/Directory&amp;gt;&lt;br /&gt;
    &amp;lt;Directory /home/admin/wwwroot/dolibarr/htdocs/.well-known/&amp;gt;&lt;br /&gt;
        AuthType None&lt;br /&gt;
        Satisfy any&lt;br /&gt;
        Require all granted&lt;br /&gt;
    &amp;lt;/Directory&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;Files ~ &amp;quot;(document\.php|viewimage\.php|\.js\.php|\.json\.php|\.js|\.css\.php|\.css|\.gif|\.png|\.svg|\.woff2|favicon\.ico)$&amp;quot;&amp;gt; &lt;br /&gt;
        AuthType None &lt;br /&gt;
        Require all granted &lt;br /&gt;
        Satisfy any&lt;br /&gt;
    &amp;lt;/Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    # And to support/manage the disconnetion&lt;br /&gt;
    RewriteEngine on&lt;br /&gt;
    RewriteCond %{REQUEST_URI} /user/logout.php&lt;br /&gt;
    RewriteRule ^ /sso_redirect?logout= [R,L]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the example above, the information to enter in OIDCProviderMetadataURL, OIDCClientID and OIDCClientSecret is provided by your OpenID Connect provider.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;OIDCRemoteUserClaim&#039;&#039;&#039; variable defines which &amp;quot;claim&amp;quot; will be used for the username. In our configuration example, we consider that the username that will be used in Dolibarr is what precedes the at sign in the email address.&lt;br /&gt;
&lt;br /&gt;
After this manipulation, you should be prompted to log in to your OpenID Connect account to access your Dolibarr installation. However, it remains to indicate to Dolibarr that it must use the username defined by Apache. It is in the &#039;&#039;&#039;conf/conf.php&#039;&#039;&#039; file that we will perform this manipulation. Add the following line at the end of the file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ini&amp;quot;&amp;gt;&lt;br /&gt;
$dolibarr_main_authentication=&#039;http&#039;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Your OpenID Connect authentication is now fully functional! Be careful however, there may be adjustments to make for this configuration to work with certain modules.&lt;br /&gt;
&lt;br /&gt;
For example, the use of WebDav in Dolibarr (pages /dav/*) is not compatible with this configuration, or access to public pages (pages /public/*) or access to APIs (pages /api/*), will be blocked by the authentication request put in place. To avoid this, you must also exclude the paths which should not be protected by the Apache authentication for OpenID which defines the protected Directory. Here is an example configuration file of your apache virtual host to be able to use &amp;quot;http&amp;quot; authentication without blocking access to public pages (retrieve the exclusion under the line &amp;quot;# Leaving /public and /api, /dav, .well_known...&amp;quot; in this example):&lt;br /&gt;
&lt;br /&gt;
https://github.com/Dolibarr/dolibarr/blob/develop/dev/setup/apache/virtualhost&lt;br /&gt;
&lt;br /&gt;
By further adapting this configuration, it is also possible to use Active Directory authentication and other authentication services.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jonbendtsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.dolibarr.org/index.php?title=Authentication,_SSO_and_SSL&amp;diff=64604</id>
		<title>Authentication, SSO and SSL</title>
		<link rel="alternate" type="text/html" href="https://wiki.dolibarr.org/index.php?title=Authentication,_SSO_and_SSL&amp;diff=64604"/>
		<updated>2025-10-29T18:33:26Z</updated>

		<summary type="html">&lt;p&gt;Jonbendtsen: /* Dolibarr application setup */ Stating where to find the openid connect configuration&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Core]]&lt;br /&gt;
&lt;br /&gt;
=Authentication setup in Dolibarr=&lt;br /&gt;
&lt;br /&gt;
There is different solutions to be authenticated with Dolibarr. You can set the selected authentication method into the file &#039;&#039;&#039;htdocs/conf/conf.php&#039;&#039;&#039; in the parameter &#039;&#039;&#039;$dolibarr_authentication_mode&#039;&#039;&#039;. This is a list of available values:&lt;br /&gt;
&lt;br /&gt;
*dolibarr&lt;br /&gt;
*http&lt;br /&gt;
*ldap&lt;br /&gt;
*forceuser&lt;br /&gt;
*googleoauth (for Google OAuth 2 authentication, Dolibarr 18+)...&lt;br /&gt;
&lt;br /&gt;
You can combine several methods (some combinations are however technically not compatible). If you use several method (separated by a coma), you will try to authenticate using the first method and if it fails, the next method will be used. For example, if you set &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$dolibarr_authentication_mode=&amp;quot;ldap,dolibarr&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
the system will try to authenticate using the LDAP database and if it fails it will try to login using the internal Dolibarr login/password&lt;br /&gt;
&lt;br /&gt;
Each authentication mode may have complementary parameters (also into htdocs/conf/conf.php file) to have them working.&lt;br /&gt;
Let&#039;s have a look at each available method:&lt;br /&gt;
&lt;br /&gt;
=Description of available authentication modes=&lt;br /&gt;
&lt;br /&gt;
==Mode dolibarr==&lt;br /&gt;
With this method, the login and pass you entered on login page will be compared to the login and the hashed password saved into the Dolibarr database ([[Table llx_user]]).&lt;br /&gt;
&lt;br /&gt;
==Mode http==&lt;br /&gt;
You can set the authentication mode to &amp;quot;http&amp;quot; if your Dolibarr web application is protected by an Apache http basic authentication form. The login/pass are stored into the file used by the HTTP Basic system to store passwords (it is often a file called &#039;&#039;&#039;.htpasswd&#039;&#039;&#039; if you used the &#039;&#039;&#039;mod_auth_basic&#039;&#039;&#039; + &#039;&#039;&#039;mod_authn_file&#039;&#039;&#039; plugin of Apache).&lt;br /&gt;
&lt;br /&gt;
This is an exemple of setup for Apache to protect your instance to be accessed using the HTTP Basic authentication (uncomment the section under line &amp;quot;# To restrict access by a HTTP basic auth&amp;quot; in this example)&lt;br /&gt;
&lt;br /&gt;
https://github.com/Dolibarr/dolibarr/blob/develop/dev/setup/apache/virtualhost&lt;br /&gt;
&lt;br /&gt;
Note that the user must also exists as a existing user into the Dolibarr user database. Also the date of validity of this user must be valid.&lt;br /&gt;
&lt;br /&gt;
==Mode ldap==&lt;br /&gt;
If you set the authentication mode to LDAP, the test of the validity of your login and password are done using a LDAP database.&lt;br /&gt;
&lt;br /&gt;
The parameters to define where is your LDAP must be defined into the variable  &#039;&#039;&#039;$dolibarr_main_auth_ldap_...&#039;&#039;&#039; (Fo security purpose, the parameters defined into the LDAP module of Dolibarr are used only by the pages of the application that need LDAP access, but for the authentication, only variables defined into the conf/conf.php file are used)&lt;br /&gt;
&lt;br /&gt;
See the file https://github.com/Dolibarr/dolibarr/blob/develop/htdocs/conf/conf.php.example for the list of $dolibarr_main_auth_ldap_... variables.&lt;br /&gt;
&lt;br /&gt;
Note that the user must also exists as an existing user into the Dolibarr user database. Also the date of validity of this user must be valid.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mode forceuser==&lt;br /&gt;
When this method is used, there is no need to enter a login or password. No login page is shown. The user will be automatically set to the one defined into the variable &#039;&#039;&#039;$dolibarr_auto_user&#039;&#039;&#039; saved into  &#039;&#039;&#039;htdocs/conf/conf.php&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This mode is used only on development platforms. For example on an instance used to make demo or automated tests.&lt;br /&gt;
&lt;br /&gt;
Note that the user must also exists as a existing user into the Dolibarr user database. Also the date of validity of this user must be valid.&lt;br /&gt;
&lt;br /&gt;
==Mode googleoauth==&lt;br /&gt;
This code is to use the Google OAuth 2 authentication. It is available with version 18+.&lt;br /&gt;
&lt;br /&gt;
*First enable the [[Module OAuth]] on Dolibarr.&lt;br /&gt;
*Into the setup of the module, you must create an OAuth entry for provider Google and label &amp;quot;&#039;&#039;&#039;Login&#039;&#039;&#039;&amp;quot; (no other label will works). You will find a value for a &#039;&#039;&#039;Redirect URI&#039;&#039;&#039; that you must use in the next step.&lt;br /&gt;
*Go on Google console https://console.cloud.google.com/ - Menu API and services - Credentials, and create an &#039;&#039;&#039;OAuth ID client&#039;&#039;&#039;. You must use the URL found at previous step as &#039;&#039;&#039;Authorized redirect URIs&#039;&#039;&#039;.&lt;br /&gt;
*Go back to the Dolibarr OAuth setup page to enter the &#039;&#039;&#039;client ID&#039;&#039;&#039; and &#039;&#039;&#039;secret ID&#039;&#039;&#039; of the OAuth entry you have created. Choose the scope/permissions &amp;quot;&#039;&#039;&#039;openid&#039;&#039;&#039;&amp;quot; and &amp;quot;&#039;&#039;&#039;email&#039;&#039;&#039;&amp;quot;.&lt;br /&gt;
*Edit the file conf/conf.php and set $dolibarr_main_authentication to &amp;quot;googleoauth&amp;quot; or &amp;quot;dolibarr,googleoauth&amp;quot; to allow both authentication with Dolibarr login/pass and with Google OAuth2&lt;br /&gt;
&lt;br /&gt;
Now try to login. You must enter your Google account and you will be able to login without password if and only if a user exists into the Dolibarr database with the same email address than the one used to login to Google.&lt;br /&gt;
&lt;br /&gt;
==Mode openid==&lt;br /&gt;
The method &amp;quot;openid&amp;quot; is an old method for using openID.&lt;br /&gt;
Try to use instead the next method &amp;quot;openid_connect&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==Mode openid_connect==&lt;br /&gt;
&lt;br /&gt;
===OpenID Connect using the native method===&lt;br /&gt;
This is a new method available with Dolibarr v18 to connect using OpenID Connect.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====In the Dolibarr conf file====&lt;br /&gt;
&lt;br /&gt;
#Configure the authentication methods in &amp;lt;code&amp;gt;conf.php&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;/var/www/html/conf/conf.php&amp;lt;/code&amp;gt;) and add &amp;lt;code&amp;gt;openid_connect&amp;lt;/code&amp;gt;. For e.g.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$dolibarr_main_authentication=&#039;openid_connect,dolibarr&#039;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Dolibarr application setup====&lt;br /&gt;
&lt;br /&gt;
Then you must set parameters and options of your openid connect service. In development branch commit 4c84650e39d5ce97c38f55e06ab0d47fe5df0435 the you can not seem to search for this openid module, but follow this path: Top menu Home, left menu Security, tab called &#039;Configuration of the OpenID Connect module&#039;. From v21, you can enable the module OpenIDConnect to edit them. From v18 to v20, you must edit them from menu &#039;&#039;&#039;Home - Setup - Other&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Name&lt;br /&gt;
!Example&lt;br /&gt;
!Comment&lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;MAIN_AUTHENTICATION_OIDC_CLIENT_ID&amp;lt;/code&amp;gt;&lt;br /&gt;
|&amp;lt;code&amp;gt;My-Super-Awesome-Client-ID-1234&amp;lt;/code&amp;gt;&lt;br /&gt;
|OpenID Connect Client ID&lt;br /&gt;
|Application client ID&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;MAIN_AUTHENTICATION_OIDC_CLIENT_SECRET&amp;lt;/code&amp;gt;&lt;br /&gt;
|&amp;lt;code&amp;gt;My-Very-Hidden-Client-Secret-1234&amp;lt;/code&amp;gt;&lt;br /&gt;
|OpenID Connect Client Secret&lt;br /&gt;
|Application client secret&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;MAIN_AUTHENTICATION_OIDC_AUTHORIZE_URL&amp;lt;/code&amp;gt;&lt;br /&gt;
|&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;https://tenant.us.auth0.com/oauth/authorize&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
|OpenID Authorize URL&lt;br /&gt;
|&amp;lt;code&amp;gt;/authorize&amp;lt;/code&amp;gt; endpoint&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;MAIN_AUTHENTICATION_OIDC_TOKEN_URL&amp;lt;/code&amp;gt;&lt;br /&gt;
|&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;https://tenant.us.auth0.com/oauth/token&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
|OpenID Connect token URL&lt;br /&gt;
|&amp;lt;code&amp;gt;/token&amp;lt;/code&amp;gt; endpoint&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;MAIN_AUTHENTICATION_OIDC_USERINFO_URL&amp;lt;/code&amp;gt;&lt;br /&gt;
|&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;https://tenant.us.auth0.com/userinfo&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
|OpenID Connect userinfo URL&lt;br /&gt;
|&amp;lt;code&amp;gt;/userinfo&amp;lt;/code&amp;gt; endpoint&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;MAIN_AUTHENTICATION_OIDC_REDIRECT_URL&amp;lt;/code&amp;gt;&lt;br /&gt;
|&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;https://dolibarr.domain.com/?openid_mode=true&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
|OpenID Connect redirect URL&lt;br /&gt;
|Dolibarr URL followed by &amp;lt;code&amp;gt;/?openid_mode=true&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;MAIN_AUTHENTICATION_OIDC_LOGIN_CLAIM&amp;lt;/code&amp;gt;&lt;br /&gt;
|&amp;lt;code&amp;gt;email&amp;lt;/code&amp;gt;&lt;br /&gt;
|OpenID Connect login claim&lt;br /&gt;
|OpenID Connect claim matching the Dolibarr user login. If not set or empty, defaults to &amp;lt;code&amp;gt;email&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;MAIN_LOGOUT_GOTO_URL&amp;lt;/code&amp;gt;&lt;br /&gt;
|See later&lt;br /&gt;
|Identity Provider logout URL&lt;br /&gt;
|Composed IdP logout URL&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Source page https://github.com/Dolibarr/dolibarr/issues/22740.&lt;br /&gt;
&lt;br /&gt;
====Composing &amp;lt;code&amp;gt;MAIN_AUTHENTICATION_OPENID_URL&amp;lt;/code&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
The MAIN_AUTHENTICATION_OPENID_URL will be generated (but if you prefer, you can set it manually from Home - Setup - Other) to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
MAIN_AUTHENTICATION_OIDC_AUTHORIZE_URL?client_id=MAIN_AUTHENTICATION_OIDC_CLIENT_ID&amp;amp;redirect_uri=mydolibarr/core/modules/openid_connect/callback.php&amp;amp;scope=MAIN_AUTHENTICATION_OIDC_SCOPES&amp;amp;response_type=code&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is the main OpenID Connect authentication URL, which allows the user to log in and then be redirected back to Dolibarr. It makes use of some already existing OpenID 2.0 features.&lt;br /&gt;
&lt;br /&gt;
#Retrieve the &amp;lt;code&amp;gt;/authorize&amp;lt;/code&amp;gt; endpoint of your OpenID server. The value depends on the used Identity Provider.  E.g.: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;https://tenant.us.auth0.com/authorize&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
#Build the URL parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Param name&lt;br /&gt;
!Description&lt;br /&gt;
!Example&lt;br /&gt;
|-&lt;br /&gt;
|client_id&lt;br /&gt;
|Application client ID&lt;br /&gt;
|&amp;lt;code&amp;gt;My-Super-Awesome-Client-ID-1234&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|redirect_uri&lt;br /&gt;
|Dolibarr URL followed by &amp;lt;code&amp;gt;/?openid_mode=true&amp;lt;/code&amp;gt;, then URL encoded. Must be authorized as callback URL&lt;br /&gt;
|Before URL encoding: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;https://dolibarr.domain.com/?openid_mode=true&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; - After URL encoding: &amp;lt;code&amp;gt;https%3A%2F%2Fdolibarr.domain.com%2F%3Fopenid_mode%3Dtrue&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|scope&lt;br /&gt;
|OpenID scope of required user info&lt;br /&gt;
|&amp;lt;code&amp;gt;openid profile email&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|response_type&lt;br /&gt;
|OAuth flow name, here we use &amp;lt;code&amp;gt;code&amp;lt;/code&amp;gt; for the Authorization Code flow&lt;br /&gt;
|&amp;lt;code&amp;gt;code&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|state&lt;br /&gt;
|A number&lt;br /&gt;
|1234568&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The final MAIN_AUTHENTICATION_OPENID_URL content should be like:  &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;https://tenant.us.auth0.com/authorize?client_id=My-Super-Awesome-Client-ID-1234&amp;amp;redirect_uri=https%3A%2F%2Fdolibarr.domain.com%2F%3Fopenid_mode%3Dtrue&amp;amp;scope=openid&amp;lt;/nowiki&amp;gt; profile email&amp;amp;response_type=code&amp;amp;state=anumber&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Composing &amp;lt;code&amp;gt;MAIN_LOGOUT_GOTO_URL&amp;lt;/code&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
#Retrieve the &amp;lt;code&amp;gt;/logout&amp;lt;/code&amp;gt; endpoint. The value depends on the used Identity Provider.  E.g.: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;https://tenant.us.auth0.com/v2/logout&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;Build the URL parameters&lt;br /&gt;
#Build the URL parameters&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Param name&lt;br /&gt;
!Description&lt;br /&gt;
!Example&lt;br /&gt;
|-&lt;br /&gt;
|client_id&lt;br /&gt;
|Application client ID&lt;br /&gt;
|&amp;lt;code&amp;gt;My-Super-Awesome-Client-ID-1234&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|returnTo&lt;br /&gt;
|URL to be redirected to after logout. Use Dolibarr URL. Must be authorized as logout URL&lt;br /&gt;
|&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;https://dolibar.domain.com&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
#The final MAIN_LOGOUT_GOTO_URL content should be like:  &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;https://tenant.us.auth0.com/v2/logout?client_id=My-Super-Awesome-Client-ID-1234&amp;amp;returnTo=https://dolibar.domain.com&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===OpenID Connect using OpenID and the HTTP Basic of Apache===&lt;br /&gt;
If you need to connect using OpenID Connect without using the native method (for example for Dolibarr &amp;lt; 18), you can also do it using the following solution:&lt;br /&gt;
&lt;br /&gt;
The idea is to use two elements:&lt;br /&gt;
&lt;br /&gt;
*The auth_openidc plugin for Apache&lt;br /&gt;
*Dolibarr HTTP authentication.&lt;br /&gt;
&lt;br /&gt;
The procedure will therefore require Dolibarr installed with Apache and the apache module https://github.com/zmartzone/mod_auth_openidc. The latter is often directly available on Linux via a package manager command.&lt;br /&gt;
&lt;br /&gt;
The second part will therefore be to configure this apache module in order to authenticate users with the OpenID Connect protocol. In the general case, you will only need the metadata URL.&lt;br /&gt;
Here is an example apache configuration for OpenID with AzureAD:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ini&amp;quot;&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
    OIDCProviderMetadataURL https://login.microsoftonline.com/your-tenant-id/v2.0/.well-known/openid-configuration&lt;br /&gt;
    OIDCClientID youropenidclient&lt;br /&gt;
    OIDCClientSecret yoursecret&lt;br /&gt;
    OIDCCryptoPassphrase randomstring&lt;br /&gt;
    OIDCRedirectURI https://mydolibarr.example.com/sso_redirect&lt;br /&gt;
    OIDCScope &amp;quot;openid email profile&amp;quot;&lt;br /&gt;
    OIDCRemoteUserClaim email ^(.*)@&lt;br /&gt;
&lt;br /&gt;
    # Disable openid-connect if using DoliDroid&lt;br /&gt;
    SetEnvIf User-Agent DoliDroid no-auth&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;Directory /home/.../htdocs&amp;gt;&lt;br /&gt;
        # Docroot&lt;br /&gt;
        AuthType openid-connect&lt;br /&gt;
        Require valid-user&lt;br /&gt;
        Require env no-auth&lt;br /&gt;
    &amp;lt;/Directory&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    # Disallow openid-connect on some public pages or services&lt;br /&gt;
    # Leaving /public and /api, /dav, .well_known but also wrappers for document, viewimage and public json/img accessible to everyone&lt;br /&gt;
    &amp;lt;Directory /home/admin/wwwroot/dolibarr/htdocs/public/&amp;gt;&lt;br /&gt;
        AuthType None&lt;br /&gt;
        Satisfy any&lt;br /&gt;
        Require all granted&lt;br /&gt;
    &amp;lt;/Directory&amp;gt;&lt;br /&gt;
    &amp;lt;Directory /home/admin/wwwroot/dolibarr/htdocs/api/&amp;gt;&lt;br /&gt;
        AuthType None&lt;br /&gt;
        Satisfy any&lt;br /&gt;
        Require all granted&lt;br /&gt;
    &amp;lt;/Directory&amp;gt;&lt;br /&gt;
    &amp;lt;Directory /home/admin/wwwroot/dolibarr/htdocs/dav/&amp;gt;&lt;br /&gt;
        AuthType None&lt;br /&gt;
        Satisfy any&lt;br /&gt;
        Require all granted&lt;br /&gt;
    &amp;lt;/Directory&amp;gt;&lt;br /&gt;
    &amp;lt;Directory /home/admin/wwwroot/dolibarr/htdocs/.well-known/&amp;gt;&lt;br /&gt;
        AuthType None&lt;br /&gt;
        Satisfy any&lt;br /&gt;
        Require all granted&lt;br /&gt;
    &amp;lt;/Directory&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;Files ~ &amp;quot;(document\.php|viewimage\.php|\.js\.php|\.json\.php|\.js|\.css\.php|\.css|\.gif|\.png|\.svg|\.woff2|favicon\.ico)$&amp;quot;&amp;gt; &lt;br /&gt;
        AuthType None &lt;br /&gt;
        Require all granted &lt;br /&gt;
        Satisfy any&lt;br /&gt;
    &amp;lt;/Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    # And to support/manage the disconnetion&lt;br /&gt;
    RewriteEngine on&lt;br /&gt;
    RewriteCond %{REQUEST_URI} /user/logout.php&lt;br /&gt;
    RewriteRule ^ /sso_redirect?logout= [R,L]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the example above, the information to enter in OIDCProviderMetadataURL, OIDCClientID and OIDCClientSecret is provided by your OpenID Connect provider.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;OIDCRemoteUserClaim&#039;&#039;&#039; variable defines which &amp;quot;claim&amp;quot; will be used for the username. In our configuration example, we consider that the username that will be used in Dolibarr is what precedes the at sign in the email address.&lt;br /&gt;
&lt;br /&gt;
After this manipulation, you should be prompted to log in to your OpenID Connect account to access your Dolibarr installation. However, it remains to indicate to Dolibarr that it must use the username defined by Apache. It is in the &#039;&#039;&#039;conf/conf.php&#039;&#039;&#039; file that we will perform this manipulation. Add the following line at the end of the file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ini&amp;quot;&amp;gt;&lt;br /&gt;
$dolibarr_main_authentication=&#039;http&#039;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Your OpenID Connect authentication is now fully functional! Be careful however, there may be adjustments to make for this configuration to work with certain modules.&lt;br /&gt;
&lt;br /&gt;
For example, the use of WebDav in Dolibarr (pages /dav/*) is not compatible with this configuration, or access to public pages (pages /public/*) or access to APIs (pages /api/*), will be blocked by the authentication request put in place. To avoid this, you must also exclude the paths which should not be protected by the Apache authentication for OpenID which defines the protected Directory. Here is an example configuration file of your apache virtual host to be able to use &amp;quot;http&amp;quot; authentication without blocking access to public pages (retrieve the exclusion under the line &amp;quot;# Leaving /public and /api, /dav, .well_known...&amp;quot; in this example):&lt;br /&gt;
&lt;br /&gt;
https://github.com/Dolibarr/dolibarr/blob/develop/dev/setup/apache/virtualhost&lt;br /&gt;
&lt;br /&gt;
By further adapting this configuration, it is also possible to use Active Directory authentication and other authentication services.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jonbendtsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.dolibarr.org/index.php?title=Universal_Search_Filter_Syntax&amp;diff=62604</id>
		<title>Universal Search Filter Syntax</title>
		<link rel="alternate" type="text/html" href="https://wiki.dolibarr.org/index.php?title=Universal_Search_Filter_Syntax&amp;diff=62604"/>
		<updated>2025-02-22T22:18:55Z</updated>

		<summary type="html">&lt;p&gt;Jonbendtsen: Added description for how to search in the API inclusive how to search among array_options/complementary atteibutes/extrafields&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!-- BEGIN origin interlang links --&amp;gt;&lt;br /&gt;
&amp;lt;!-- You can edit this section but do NOT remove these comments&lt;br /&gt;
     Links below will be automatically replicated on translated pages by PolyglotBot --&amp;gt;&lt;br /&gt;
&amp;lt;!-- END interlang links --&amp;gt;&lt;br /&gt;
[[Category:Admin_en]]&lt;br /&gt;
{{TemplateDocDevEn}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Universal Search Filter (also mentioned as USF) is the technical syntax, provided to developers, to define a filter in Dolibarr ERP CRM application.&lt;br /&gt;
&lt;br /&gt;
=When to use the USF=&lt;br /&gt;
It is used by developers to:&lt;br /&gt;
&lt;br /&gt;
*build rules to filter some combo list, defined when creating a new object or property (into the property -&amp;gt;fields of an object class file)&lt;br /&gt;
*build condition for some properties of extrafields (set into the page to edit extrafields).&lt;br /&gt;
*to provide filters to some functions and methods into Dolibarr internal code.&lt;br /&gt;
*to provide filters to some Ajax components.&lt;br /&gt;
*to define filters on requests of APIs.&lt;br /&gt;
*to propagate securely filters in some tools, for example in the customreport.php tools.&lt;br /&gt;
&lt;br /&gt;
In old version, all this use cases were using a different syntax. Transition was done to use the same one everywhere, between v17 and was completed in v20 (see next chapter why).&lt;br /&gt;
&lt;br /&gt;
=Why to use the USF=&lt;br /&gt;
The USF syntax has been introduced for two main reason:&lt;br /&gt;
&lt;br /&gt;
*To provide a secured way to propagate a filter from a component to another one, with no risk of injections.&lt;br /&gt;
*To provide a generic solution to define a filter that follows structured rules making possible to convert it easily and programmaticaly into the expected language, whatever is this language (most often in SQL but also in PHP or Javascript).&lt;br /&gt;
&lt;br /&gt;
=Syntax of USF=&lt;br /&gt;
A simple test in USF syntax is forged this way: Open parenthesis, then the first operand that is the field, then the character &amp;quot;:&amp;quot;, then the operator, then the character &amp;quot;:&amp;quot;, then the second operand that is the value, then the closing parenthesis.&lt;br /&gt;
&lt;br /&gt;
*The first operator allows only the following characters: a to z, 0 to 9, _, - and .&lt;br /&gt;
&lt;br /&gt;
*The operator can be: =, &amp;lt;, &amp;gt;, &amp;lt;=, &amp;gt;=, !=, in, notin, like, notlike, is, isnot (and nothing else).&lt;br /&gt;
&lt;br /&gt;
*If the value is a string, you must add simple quotes. If value is a date, it must use the international format into simple quotes (&#039;YYYY-MM-DD&#039; or &#039;YYYY-MM-DD HH:MM:SS&#039;) in the timezone of the server.&lt;br /&gt;
&lt;br /&gt;
When using the &amp;quot;in&amp;quot; or &amp;quot;notin&amp;quot; operator, the character &amp;quot;,&amp;quot; must be used to separate each possible value, the character &amp;quot;,&amp;quot; can&#039;t be used inside the value. When using the operator &amp;quot;is&amp;quot; or &amp;quot;isnot&amp;quot;, the only allowed value is &amp;quot;null&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Then, you can combine any simple test using &#039;&#039;&#039;parenthesis&#039;&#039;&#039; and &#039;&#039;&#039;OR&#039;&#039;&#039; or &#039;&#039;&#039;AND&#039;&#039;&#039; to forge combined tests.&lt;br /&gt;
&lt;br /&gt;
Example of simple tests:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
(myfield:=:&#039;mystringvalue&#039;)&lt;br /&gt;
(myfield:&amp;gt;=:123.45)&lt;br /&gt;
(t.mydatefield:&amp;gt;:&#039;2024-01-01 10:00:00&#039;)&lt;br /&gt;
(myfield:like:&#039;asubstring&#039;)&lt;br /&gt;
(myfield:isnot:null)&lt;br /&gt;
(myintfield:in:1,2,3,4,5)&lt;br /&gt;
(mystringfield:in:&#039;1&#039;,&#039;2&#039;,&#039;3&#039;,&#039;4&#039;,&#039;5&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of combined tests:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
((myfield:=:&#039;mystringvalue&#039;) OR (myfield2:&amp;gt;=:myintorfloatvalue))&lt;br /&gt;
((myfield:=:&#039;mystringvalue&#039;) OR ((myfield2:&amp;gt;=:myintorfloatvalue) AND (myfield3:&amp;gt;:&#039;2024-01-01 10:00:00&#039;)))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Convert USF in SQL=&lt;br /&gt;
Dolibarr provide a method to validate, and convert an USF into a sanitized SQL string:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
$errorstring = &#039;&#039;;&lt;br /&gt;
$sqlcode = forgeSQLFromUniversalSearchCriteria(&#039;string_with_usf_syntax&#039;, $errorstring);&lt;br /&gt;
if (!$errorstring) {&lt;br /&gt;
    // Here the $sqlcode is a valid SQL &amp;quot;where&amp;quot; string&lt;br /&gt;
} else {&lt;br /&gt;
    // Here the $sqlcode is not valid&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the USF has a wrong syntax, the function will return the error into the $errorstring variable.&lt;br /&gt;
&lt;br /&gt;
== Using sqlfilters in the API ==&lt;br /&gt;
Universal Search Filter Syntax can be very useful in the API to narrow down your search results. Generally the base columns for an object can be referenced as t.tosell, t.status, t.projet, ... unfortunately there is not always a 1:1 correlation with the key name in the JSON output and the column name in the database. You might also want to search array_options/Complementary attributes/extrafields, which is entirely possible, as long as you remember that if your key in the JSON output under array_options is called options_service_type, then you have to write it as ef.service_type in the sqlfilters in the API.&lt;/div&gt;</summary>
		<author><name>Jonbendtsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.dolibarr.org/index.php?title=Module_Web_Services_API_REST_(developer)&amp;diff=61050</id>
		<title>Module Web Services API REST (developer)</title>
		<link rel="alternate" type="text/html" href="https://wiki.dolibarr.org/index.php?title=Module_Web_Services_API_REST_(developer)&amp;diff=61050"/>
		<updated>2024-08-03T16:04:15Z</updated>

		<summary type="html">&lt;p&gt;Jonbendtsen: inserted link to Dolibarrpy and put year numbers after all 3 modules with the latest release.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!-- BEGIN origin interlang links --&amp;gt;&lt;br /&gt;
&amp;lt;!-- You can edit this section but do NOT remove these comments&lt;br /&gt;
     Links below will be automatically replicated on translated pages by PolyglotBot --&amp;gt;&lt;br /&gt;
[[fr:Module_Web_Services_API_REST_(développeur)]]&lt;br /&gt;
[[ja:Module_Web_Services_API_REST_(developer)_JA]]&lt;br /&gt;
[[zh:提供REST_API的Web服务模块（开发者）]]&lt;br /&gt;
&amp;lt;!-- END interlang links --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{TemplateDocDevEn}}&lt;br /&gt;
{{TemplateModEN}}&lt;br /&gt;
[[Category:List of Modules]]&lt;br /&gt;
{{BasculeDevUserEn|&lt;br /&gt;
name=Web services|&lt;br /&gt;
num=2610|&lt;br /&gt;
devdoc=This page|&lt;br /&gt;
userdoc=Not applicable|}}&lt;br /&gt;
&lt;br /&gt;
=Function=&lt;br /&gt;
When enabling this module, you enable usage of web services provided by Dolibarr server. You can then make REST call of different web services provided by Dolibarr.&lt;br /&gt;
&lt;br /&gt;
=Installation=&lt;br /&gt;
&lt;br /&gt;
To install, open the modules page and activate de &amp;quot;API REST&amp;quot; module. &lt;br /&gt;
&lt;br /&gt;
Once module webservices REST is activated, Dolibarr become also a server of REST web services. So you can send your own REST request to relative URL&lt;br /&gt;
&#039;&#039;&#039;/api/index.php/xxx&#039;&#039;&#039; where xxx is name of the API to call.&lt;br /&gt;
&lt;br /&gt;
A list of APIs on your installation can be found via the explorer. Click on link to explorer to open the API explorer.&lt;br /&gt;
&lt;br /&gt;
==Apache setup==&lt;br /&gt;
There is nothing to do. If your Dolibarr is working with Apache, the REST API should also work. APIs will be served by the same virtual web server than your application.&lt;br /&gt;
&lt;br /&gt;
==Nginx setup==&lt;br /&gt;
Like Apache, if your Dolibarr is working inside a NGinx virtual host, you should have nothing to do to have your API working. APIs will be served by the same virtual web server than your application.&lt;br /&gt;
&lt;br /&gt;
However, NGinx default setup on a lot of distribution is often a gaz engine and you may experience troubles. If you experience such troubles, you can try to edit your NGinx config file to match the following example. This is a simple localhost setup with a working REST API handling (tested with 9.0.1 on parabola gnu/linux).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nginx&amp;quot;&amp;gt;&lt;br /&gt;
worker_processes  1;&lt;br /&gt;
error_log  /var/log/nginx/error.log;&lt;br /&gt;
&lt;br /&gt;
events {&lt;br /&gt;
    worker_connections  1024;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
http {&lt;br /&gt;
    include       mime.types;&lt;br /&gt;
    default_type  application/octet-stream;&lt;br /&gt;
&lt;br /&gt;
    #log_format  main  &#039;$remote_addr - $remote_user [$time_local] &amp;quot;$request&amp;quot; &#039;&lt;br /&gt;
    #                  &#039;$status $body_bytes_sent &amp;quot;$http_referer&amp;quot; &#039;&lt;br /&gt;
    #                  &#039;&amp;quot;$http_user_agent&amp;quot; &amp;quot;$http_x_forwarded_for&amp;quot;&#039;;&lt;br /&gt;
&lt;br /&gt;
    #access_log  logs/access.log  main;&lt;br /&gt;
&lt;br /&gt;
    sendfile        on;&lt;br /&gt;
    #tcp_nopush     on;&lt;br /&gt;
&lt;br /&gt;
    #keepalive_timeout  0;&lt;br /&gt;
    keepalive_timeout  65;&lt;br /&gt;
&lt;br /&gt;
    #gzip  on;&lt;br /&gt;
&lt;br /&gt;
    server {&lt;br /&gt;
    	listen		80;&lt;br /&gt;
        server_name     dolibarr.localhost; # adjust to your domain&lt;br /&gt;
&lt;br /&gt;
        root    /usr/share/webapps/dolibarr/htdocs; # adjust to your path &lt;br /&gt;
        index   index.php;&lt;br /&gt;
&lt;br /&gt;
        # from https://github.com/Dolibarr/dolibarr/issues/6163#issuecomment-391265538&lt;br /&gt;
        location ~ [^/]\.php(/|$) {&lt;br /&gt;
            fastcgi_split_path_info ^(.+?\.php)(/.*)$;&lt;br /&gt;
            if (!-f $document_root$fastcgi_script_name) {&lt;br /&gt;
                return 404;&lt;br /&gt;
            }&lt;br /&gt;
&lt;br /&gt;
            # Mitigate https://httpoxy.org/ vulnerabilities&lt;br /&gt;
            fastcgi_param HTTP_PROXY &amp;quot;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
            root           /usr/share/webapps/dolibarr/htdocs;&lt;br /&gt;
            fastcgi_pass   unix:/run/php-fpm/php-fpm.sock;&lt;br /&gt;
            fastcgi_index  index.php;&lt;br /&gt;
            include        fastcgi_params;&lt;br /&gt;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;&lt;br /&gt;
            # Dolibarr Rest API path support&lt;br /&gt;
            fastcgi_param  PATH_INFO       $fastcgi_path_info;&lt;br /&gt;
            fastcgi_param  PATH_TRANSLATED $document_root$fastcgi_script_name;&lt;br /&gt;
        }&lt;br /&gt;
     }		&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=List of provided services=&lt;br /&gt;
Only few services are available. You can see full list of Dolibarr Web services provided, by calling the explorer here at address:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;http://yourdolibarrurl/api/index.php/explorer&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
For example, you can try the explorer on the demo instance at:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;https://demo.dolibarr.org/api/index.php/explorer&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
On the top right corner, paste the &amp;lt;token&amp;gt; of the user you want to use to call the API and click the &amp;quot;explore&amp;quot; button. Note: The token of each user can be defined on the user record page. &lt;br /&gt;
If you prefer, you can first make a first call to the &#039;&#039;&#039;login&#039;&#039;&#039; API to get the API token key. Then enter API key to get list of all other available API services.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After clicking on &amp;quot;Explore&amp;quot;, you should see all the actions available with this token. If you don&#039;t have a lot of actions, it&#039;s probably because the according modules are not activated. If you want to see the invoices, you have to activate the invoice module in the configuration of Dolibarr. Same for products, third parties and so on.&lt;br /&gt;
&lt;br /&gt;
On this exploration page of the API, you can do quite a lot of tests. Reading datas from Dolibarr and writing, modifying and deleting as well. Warning: Data are really modified in your database.&lt;br /&gt;
&lt;br /&gt;
You can then test directly from the explorer tool any API. This is the recommended solution to test any Dolibarr API since any API and parameters is documented here. As a result of any test, you will get the answer but also example on how to call the API from command line using &#039;&#039;&#039;curl&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=Use=&lt;br /&gt;
&lt;br /&gt;
To use the REST API,  you have to call an url such as this one : &amp;lt;nowiki&amp;gt;http://&amp;lt;my_server&amp;gt;/api/index.php/&amp;lt;action&amp;gt;&amp;lt;/nowiki&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
with one of the 4 following methods : GET, POST, PUT, DELETE, replacing &amp;lt;action&amp;gt; by the action you want to use. Ex : &amp;lt;nowiki&amp;gt;http://&amp;lt;my_server&amp;gt;/api/index.php/invoices&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Before using any API, you must first get a custom API-key. You have to create a new user and generate or set its &amp;quot;Key for API&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[File:Dolibarr user for api.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You will have to use this API key in any of your client program that need to call a Dolibarr API.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Client code example==&lt;br /&gt;
&lt;br /&gt;
===PHP===&lt;br /&gt;
There&#039;s different ways to do so. Here&#039;s a piece of code but you can also use libraries such as phphttpclient.com&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
// Example of function to call a REST API&lt;br /&gt;
function callAPI($method, $apikey, $url, $data = false)&lt;br /&gt;
{&lt;br /&gt;
    $curl = curl_init();&lt;br /&gt;
    $httpheader = [&#039;DOLAPIKEY: &#039;.$apikey];&lt;br /&gt;
&lt;br /&gt;
    switch ($method)&lt;br /&gt;
    {&lt;br /&gt;
        case &amp;quot;POST&amp;quot;:&lt;br /&gt;
            curl_setopt($curl, CURLOPT_POST, 1);&lt;br /&gt;
            $httpheader[] = &amp;quot;Content-Type:application/json&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
            if ($data)&lt;br /&gt;
                curl_setopt($curl, CURLOPT_POSTFIELDS, $data);&lt;br /&gt;
&lt;br /&gt;
            break;&lt;br /&gt;
        case &amp;quot;PUT&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
	    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, &#039;PUT&#039;);&lt;br /&gt;
            $httpheader[] = &amp;quot;Content-Type:application/json&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
            if ($data)&lt;br /&gt;
                curl_setopt($curl, CURLOPT_POSTFIELDS, $data);&lt;br /&gt;
&lt;br /&gt;
            break;&lt;br /&gt;
        default:&lt;br /&gt;
            if ($data)&lt;br /&gt;
                $url = sprintf(&amp;quot;%s?%s&amp;quot;, $url, http_build_query($data));&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // Optional Authentication:&lt;br /&gt;
    //    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);&lt;br /&gt;
    //    curl_setopt($curl, CURLOPT_USERPWD, &amp;quot;username:password&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    curl_setopt($curl, CURLOPT_URL, $url);&lt;br /&gt;
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);&lt;br /&gt;
    curl_setopt($curl, CURLOPT_HTTPHEADER, $httpheader);&lt;br /&gt;
&lt;br /&gt;
    $result = curl_exec($curl);&lt;br /&gt;
&lt;br /&gt;
    curl_close($curl);&lt;br /&gt;
&lt;br /&gt;
    return $result;&lt;br /&gt;
}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is just a working example. There&#039;s no error control and security was not in mind but you can use this code, modify it to suit your needs&amp;lt;br /&amp;gt;&lt;br /&gt;
The fonction has 4 parameters :&lt;br /&gt;
&lt;br /&gt;
*$method : string, &amp;quot;GET&amp;quot;, &amp;quot;POST&amp;quot;, &amp;quot;PUT&amp;quot;, &amp;quot;DELETE&amp;quot;&lt;br /&gt;
*$apikey : string, &amp;quot;your &amp;lt;token&amp;gt; generated earlier&amp;quot;&lt;br /&gt;
*$url : string, url to call. Ex : &amp;quot;&amp;lt;nowiki&amp;gt;http://&amp;lt;my_server&amp;gt;/api/index.php/invoices&amp;lt;/nowiki&amp;gt;&amp;quot;&lt;br /&gt;
*$data : string, datas in json format. This parameter is not mandatory.&lt;br /&gt;
&lt;br /&gt;
===Javascript Ajax===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;script&amp;gt;&lt;br /&gt;
$.ajax({&lt;br /&gt;
  type: &#039;GET&#039;,&lt;br /&gt;
  async: true,&lt;br /&gt;
  contentType: &amp;quot;application/json; charset=utf-8&amp;quot;,&lt;br /&gt;
  data: { &#039;lang&#039;: &#039;en_US&#039; },&lt;br /&gt;
  dataType: &amp;quot;json&amp;quot;,&lt;br /&gt;
  cache: false,&lt;br /&gt;
  jsonp: false,&lt;br /&gt;
  headers: {&lt;br /&gt;
    &#039;DOLAPIKEY&#039;: &#039;abcdef123456&#039;&lt;br /&gt;
  }, &lt;br /&gt;
  url: &#039;https://myserver/api/index.php/theapi&#039;,&lt;br /&gt;
  success: function(rep) {&lt;br /&gt;
    console.log(&amp;quot;API call success&amp;quot;);&lt;br /&gt;
    console.log(rep);&lt;br /&gt;
  },&lt;br /&gt;
  error: function(rep) {&lt;br /&gt;
    console.log(&amp;quot;API call error&amp;quot;);&lt;br /&gt;
    console.log(rep);&lt;br /&gt;
  }&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Accepted parameters==&lt;br /&gt;
This is documented somewhat in the REST Explorer. Check that first. Second try and see what response you get. Third look at the source code for the given API.&lt;br /&gt;
&lt;br /&gt;
===sqlfilters===&lt;br /&gt;
They are passed on to the database after a check.&lt;br /&gt;
These work on the product endpoint:&lt;br /&gt;
&lt;br /&gt;
*(t.fk_product_type: = :&#039;0&#039;) and (t.tosell: = :&#039;1&#039;) and (t.label: ilike :&#039;%string&#039;)&lt;br /&gt;
&lt;br /&gt;
===Date===&lt;br /&gt;
The ISO date format is accepted: %Y-%m-%d e.g. 2020-07-14. yymmdd is not accepted.&lt;br /&gt;
&lt;br /&gt;
=Examples with PHP=&lt;br /&gt;
&lt;br /&gt;
This is more examples, for different uses cases:&lt;br /&gt;
&lt;br /&gt;
In every examples, we have:&lt;br /&gt;
&lt;br /&gt;
*$apiKey = &amp;quot;&amp;lt;my token&amp;gt;&amp;quot;;&lt;br /&gt;
*$apiUrl = &amp;quot;&amp;lt;nowiki&amp;gt;http://&amp;lt;my_server&amp;gt;/api/index.php/&amp;lt;/nowiki&amp;gt;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
// Retrieve products list&lt;br /&gt;
	$listProduits = [];&lt;br /&gt;
	$produitParam = [&amp;quot;limit&amp;quot; =&amp;gt; 10000, &amp;quot;sortfield&amp;quot; =&amp;gt; &amp;quot;rowid&amp;quot;];&lt;br /&gt;
	$listProduitsResult = CallAPI(&amp;quot;GET&amp;quot;, $apiKey, $apiUrl.&amp;quot;products&amp;quot;, $produitParam);&lt;br /&gt;
	$listProduitsResult = json_decode($listProduitsResult, true);&lt;br /&gt;
&lt;br /&gt;
	if (isset($listProduitsResult[&amp;quot;error&amp;quot;]) &amp;amp;&amp;amp; $listProduitsResult[&amp;quot;error&amp;quot;][&amp;quot;code&amp;quot;] &amp;gt;= &amp;quot;300&amp;quot;) {&lt;br /&gt;
	} else {&lt;br /&gt;
		foreach ($listProduitsResult as $produit) {&lt;br /&gt;
			$listProduits[intval($produit[&amp;quot;id&amp;quot;])] = html_entity_decode($produit[&amp;quot;ref&amp;quot;], ENT_QUOTES);&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Comments :&lt;br /&gt;
&lt;br /&gt;
*I retrieve the 10&#039;000 first products sorted on their ID in the base&lt;br /&gt;
*html_entity_decode is necessary as single quotes are encoded&lt;br /&gt;
*It&#039;s easy to use the same method (replacing products with dictionnarycountries) to retrieve the list of countries and their ID&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
// Create a product&lt;br /&gt;
	$ref = &amp;quot;my_product_ref_X203ZZ&amp;quot;;&lt;br /&gt;
	$newProduct = [&lt;br /&gt;
		&amp;quot;ref&amp;quot;	=&amp;gt; $ref,&lt;br /&gt;
		&amp;quot;label&amp;quot;	=&amp;gt; $ref&lt;br /&gt;
	];&lt;br /&gt;
	$newProductResult = CallAPI(&amp;quot;POST&amp;quot;, $apiKey, $apiUrl.&amp;quot;products&amp;quot;, json_encode($newProduct));&lt;br /&gt;
	$newProductResult = json_decode($newProductResult, true);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Comments :&lt;br /&gt;
&lt;br /&gt;
*before creating a product, it could be wise to check if it exists. Using my first example, you&#039;ll have  :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
// my ref&lt;br /&gt;
	$ref = &amp;quot;my_product_ref_X203ZZ&amp;quot;;&lt;br /&gt;
// does it exist in my array&lt;br /&gt;
	$produitKey = array_search($ref, $listProduits);&lt;br /&gt;
	if ($produitKey) {&lt;br /&gt;
// yes&lt;br /&gt;
		$fk_product = $produitKey;&lt;br /&gt;
	} else {&lt;br /&gt;
// no&lt;br /&gt;
// Create the product&lt;br /&gt;
		$newProduct = [&lt;br /&gt;
			&amp;quot;ref&amp;quot;	=&amp;gt; $ref,&lt;br /&gt;
			&amp;quot;label&amp;quot;	=&amp;gt; $ref&lt;br /&gt;
		];&lt;br /&gt;
		$newProductResult = CallAPI(&amp;quot;POST&amp;quot;, $apiKey, $apiUrl.&amp;quot;products&amp;quot;, json_encode($newProduct));&lt;br /&gt;
		$newProductResult = json_decode($newProductResult, true);&lt;br /&gt;
		if (isset($newProductResult[&amp;quot;error&amp;quot;]) &amp;amp;&amp;amp; $newProductResult[&amp;quot;error&amp;quot;][&amp;quot;code&amp;quot;] &amp;gt;= &amp;quot;300&amp;quot;) {&lt;br /&gt;
// there&#039;s been an error&lt;br /&gt;
			echo &amp;quot;&amp;lt;pre&amp;gt;ERROR&amp;quot;, var_dump($newProductResult), &amp;quot;&amp;lt;/pre&amp;gt;&amp;quot;;&lt;br /&gt;
			exit;&lt;br /&gt;
		} else {&lt;br /&gt;
// everything good&lt;br /&gt;
			$fk_product = $newProductResult;&lt;br /&gt;
			$listProduits[$fk_product] = $ref;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Comments :&lt;br /&gt;
&lt;br /&gt;
*I check if the ref of my product exist in the array created in the first example.&lt;br /&gt;
*If it exists, I use it&#039;s key in the array as ID&lt;br /&gt;
*If it doesn&#039;t exist, I create the product, then I add it to my array for next time then I use the ID created&lt;br /&gt;
*I choose this method to do less API calls when I have to import 500 orders. I just need to retrieve the products list once at the beginning instead of searching Dolibarr each time.&lt;br /&gt;
&lt;br /&gt;
Warning: The example below is not working properly. Creating an order and lines in one go is not supported. Instead you have to create an order first and with the returned order id add the lines using the /orders/{id}/lines endpoint. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
// create an order with 2 products&lt;br /&gt;
&lt;br /&gt;
// The array where there will be all the products lines of my order.&lt;br /&gt;
	$newCommandeLine = [];&lt;br /&gt;
&lt;br /&gt;
// product 1&lt;br /&gt;
	$ref1 = &amp;quot;my_product_ref_X203ZZ&amp;quot;;&lt;br /&gt;
	$prix1 = 10;&lt;br /&gt;
	$qtt1  = 100;&lt;br /&gt;
	$tva1 = 20;&lt;br /&gt;
	$fk_product1&lt;br /&gt;
// product 2&lt;br /&gt;
	$ref2 = &amp;quot;my_product_ref_B707FD&amp;quot;;&lt;br /&gt;
	$prix2 = 13;&lt;br /&gt;
	$qtt2  = 37;&lt;br /&gt;
	$tva2 = 20;&lt;br /&gt;
&lt;br /&gt;
	$newCommandeLine[] = [&lt;br /&gt;
		&amp;quot;desc&amp;quot;		=&amp;gt; $ref1,&lt;br /&gt;
		&amp;quot;subprice&amp;quot;	=&amp;gt; $prix1,&lt;br /&gt;
		&amp;quot;qty&amp;quot;		=&amp;gt; $qtt1,&lt;br /&gt;
		&amp;quot;tva_tx&amp;quot;	=&amp;gt; floatval($tva1),&lt;br /&gt;
		&amp;quot;fk_product&amp;quot;=&amp;gt; $fk_product1&lt;br /&gt;
	];&lt;br /&gt;
&lt;br /&gt;
	$newCommandeLine[] = [&lt;br /&gt;
		&amp;quot;desc&amp;quot;		=&amp;gt; $ref2,&lt;br /&gt;
		&amp;quot;subprice&amp;quot;	=&amp;gt; $prix2,&lt;br /&gt;
		&amp;quot;qty&amp;quot;		=&amp;gt; $qtt2,&lt;br /&gt;
		&amp;quot;tva_tx&amp;quot;	=&amp;gt; floatval($tva2),&lt;br /&gt;
		&amp;quot;fk_product&amp;quot;=&amp;gt; $fk_product2&lt;br /&gt;
	];&lt;br /&gt;
&lt;br /&gt;
	if (count($newCommandeLine) &amp;gt; 0) {&lt;br /&gt;
		$newCommande = [&lt;br /&gt;
			&amp;quot;socid&amp;quot;			=&amp;gt; $clientDoliId,&lt;br /&gt;
			&amp;quot;type&amp;quot; 			=&amp;gt; &amp;quot;0&amp;quot;,&lt;br /&gt;
			&amp;quot;lines&amp;quot;			=&amp;gt; $newCommandeLine,&lt;br /&gt;
			&amp;quot;note_private&amp;quot;	=&amp;gt; &amp;quot;order created automatically with API&amp;quot;,&lt;br /&gt;
		];&lt;br /&gt;
		$newCommandeResult = CallAPI(&amp;quot;POST&amp;quot;, $apiKey, $apiUrl.&amp;quot;orders&amp;quot;, json_encode($newCommande));&lt;br /&gt;
		$newCommandeResult = json_decode($newCommandeResult, true);&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Comments :&lt;br /&gt;
&lt;br /&gt;
*$clientDoliId is the ID of the customer in the Dolibarr database. Either you know it or you can search for it before&lt;br /&gt;
*type =&amp;gt; 0, This is a customer order (while 1 = supplier order)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
// Validate an order &lt;br /&gt;
	$newCommandeValider = [&lt;br /&gt;
		&amp;quot;idwarehouse&amp;quot;	=&amp;gt; &amp;quot;0&amp;quot;,&lt;br /&gt;
		&amp;quot;notrigger&amp;quot;		=&amp;gt; &amp;quot;0&amp;quot;&lt;br /&gt;
	];&lt;br /&gt;
	$newCommandeValiderResult = CallAPI(&amp;quot;POST&amp;quot;, $apiKey, $apiUrl.&amp;quot;orders/&amp;quot;.$newCommandeResult.&amp;quot;/validate&amp;quot;, json_encode($newCommandeValider));&lt;br /&gt;
	$newCommandeValiderResult = json_decode($newCommandeValiderResult, true);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Comments :&lt;br /&gt;
&lt;br /&gt;
*in this example, on the penultimate line, we can see : $apiUrl.&amp;quot;orders/&amp;quot;.$newCommandeResult.&amp;quot;/validate&amp;quot;.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
$newCommandeResult is the ID of the order created in the previous example&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
// search in the database if a customer exist&lt;br /&gt;
	$customer_name = &amp;quot;Acme Inc&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
	$clientSearch = json_decode(CallAPI(&amp;quot;GET&amp;quot;, $apiKey, $apiUrl.&amp;quot;thirdparties&amp;quot;, array(&lt;br /&gt;
		&amp;quot;sortfield&amp;quot; =&amp;gt; &amp;quot;t.rowid&amp;quot;, &lt;br /&gt;
		&amp;quot;sortorder&amp;quot; =&amp;gt; &amp;quot;ASC&amp;quot;, &lt;br /&gt;
		&amp;quot;limit&amp;quot; =&amp;gt; &amp;quot;1&amp;quot;, &lt;br /&gt;
		&amp;quot;mode&amp;quot; =&amp;gt; &amp;quot;1&amp;quot;,&lt;br /&gt;
		&amp;quot;sqlfilters&amp;quot; =&amp;gt; &amp;quot;(t.nom:=:&#039;&amp;quot;.$customer_name.&amp;quot;&#039;)&amp;quot;&lt;br /&gt;
		)&lt;br /&gt;
	), true);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Comments :&lt;br /&gt;
&lt;br /&gt;
*limit =&amp;gt; 1 only 1 customer&lt;br /&gt;
*mode =&amp;gt; 1 we are looking for a customer, not a supplier (they are thirdparties too but with a different status)&lt;br /&gt;
*sqlfilters a bit special but there are more examples on the explorer page&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
// customer doesn&#039;t exist. Let&#039;s create it and get it&#039;s ID&lt;br /&gt;
	$newClient = [&lt;br /&gt;
		&amp;quot;name&amp;quot; 			=&amp;gt; &amp;quot;customer company name&amp;quot;,&lt;br /&gt;
		&amp;quot;email&amp;quot;			=&amp;gt; &amp;quot;customer company email&amp;quot;,&lt;br /&gt;
		&amp;quot;client&amp;quot; 		=&amp;gt; &amp;quot;1&amp;quot;,&lt;br /&gt;
		&amp;quot;code_client&amp;quot;	=&amp;gt; &amp;quot;-1&amp;quot;&lt;br /&gt;
	];&lt;br /&gt;
	$newClientResult = CallAPI(&amp;quot;POST&amp;quot;, $apiKey, $apiUrl.&amp;quot;thirdparties&amp;quot;, json_encode($newClient));&lt;br /&gt;
	$newClientResult = json_decode($newClientResult, true);&lt;br /&gt;
	$clientDoliId = $newClientResult;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Comments :&lt;br /&gt;
&lt;br /&gt;
*client =&amp;gt; 1 He is a customer (not a supplier)&lt;br /&gt;
*code_client =&amp;gt; -1 so the customer code will be generated automatically.&lt;br /&gt;
*we get the customer ID in $clientDoliId&lt;br /&gt;
&lt;br /&gt;
=Examples with Python=&lt;br /&gt;
See https://pypi.org/project/dolipy/ (2021) or https://pypi.org/project/dolibarr/ (2019) or https://pypi.org/project/dolibarrpy/ (2024)&lt;br /&gt;
&lt;br /&gt;
First you can install the python-module with &amp;quot;pip install dolibarr&amp;quot; or pypi install dolibarrpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
 from dolibarr import Dolibarr&lt;br /&gt;
&lt;br /&gt;
 api_url = &#039;&amp;lt;nowiki&amp;gt;http://your-url/dolibarr/htdocs/api/index.php/&#039;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 api_key = &#039;custom_API-Key&#039;&lt;br /&gt;
&lt;br /&gt;
 # Connection to dolibarr&lt;br /&gt;
 dolibarr_inst = Dolibarr(api_url, api_key)&lt;br /&gt;
&lt;br /&gt;
 # create Product&lt;br /&gt;
 params = {&#039;ref&#039;: &#039;Product_Reference&#039;, &#039;status&#039;: &#039;1&#039;, &#039;barcode_type&#039;: &#039;6&#039;, &#039;note_public&#039;: None,          &lt;br /&gt;
&lt;br /&gt;
           &#039;note_private&#039;: &amp;lt;nowiki&amp;gt;&#039;&#039;&amp;lt;/nowiki&amp;gt;, &#039;specimen&#039;: 0, &#039;label&#039;: &#039;Product_Label&#039;,&lt;br /&gt;
&lt;br /&gt;
           &#039;description&#039;: &amp;lt;nowiki&amp;gt;&#039;&#039;&amp;lt;/nowiki&amp;gt;, &#039;type&#039;: &#039;0&#039;, &#039;price&#039;: &amp;lt;nowiki&amp;gt;&#039;&#039;&amp;lt;/nowiki&amp;gt;, &#039;price_ttc&#039;: &#039;15.6000000&#039;, &#039;price_base_type&#039;: &#039;TTC&#039;,  # excl. tax = HT, incl. tax = TTC&lt;br /&gt;
&lt;br /&gt;
           &#039;tva_tx&#039;: &#039;19.0000&#039;, &#039;seuil_stock_alerte&#039;: &#039;0&#039;, &#039;desiredstock&#039;: &#039;0&#039;, &#039;status_buy&#039;: &#039;1&#039;, &#039;barcode&#039;: &#039;barcode&#039;}&lt;br /&gt;
&lt;br /&gt;
 ret_val = dolibarr_inst.call_create_api(&#039;products&#039;, params)&lt;br /&gt;
 print(ret_val)&lt;br /&gt;
&lt;br /&gt;
 # get product list&lt;br /&gt;
 product_dict = dolibarr_inst.call_list_api(&#039;products&#039;)&lt;br /&gt;
 print(product_dict)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Develop your own service / API=&lt;br /&gt;
Adding a new REST service is as easy than adding a file called &#039;&#039;&#039;api_mymoduleobject.class.php&#039;&#039;&#039; into the directory &#039;&#039;&#039;htdocs/mymodule/class&#039;&#039;&#039;.&lt;br /&gt;
You can take an example into &#039;&#039;&#039;htdocs/commande/class/api_orders.class.php&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Note that if you use the &#039;&#039;&#039;modulebuilder&#039;&#039;&#039; tool, this file may be generated for you.&lt;br /&gt;
&lt;br /&gt;
The framework detects automatically the API files and it should be visible into the explorer.&lt;br /&gt;
&lt;br /&gt;
Method and parameters are detected according to introspection done into PHP class of the object (&#039;&#039;&#039;htdocs/mymodule/class/object.class.php&#039;&#039;&#039;) using the &#039;&#039;&#039;annotations&#039;&#039;&#039; found into the class.&lt;br /&gt;
For a documentation about annotation: https://github.com/Luracast/Restler/blob/master/ANNOTATIONS.md&lt;br /&gt;
&lt;br /&gt;
These are just the basics.&lt;br /&gt;
&lt;br /&gt;
To find all existing API files in Dolibarr, you can search all files htdocs/&amp;lt;directory&amp;gt;/class/api_xxx_class.php&lt;/div&gt;</summary>
		<author><name>Jonbendtsen</name></author>
	</entry>
</feed>