diff --git a/htdocs/adherents/class/api_members.class.php b/htdocs/adherents/class/api_members.class.php
index 59d520945154c4bde73c8ca077d8a852317bc9b0..779b5213666e6e1c021f1e6981e4fc68210a1c55 100644
--- a/htdocs/adherents/class/api_members.class.php
+++ b/htdocs/adherents/class/api_members.class.php
@@ -143,7 +143,7 @@ class Members extends DolibarrApi
             }
         }
         else {
-            throw new RestException(503, 'Error when retrieve member list : '.$member->error);
+            throw new RestException(503, 'Error when retrieve member list : '.$db->lasterror());
         }
         if( ! count($obj_ret)) {
             throw new RestException(404, 'No member found');
@@ -289,9 +289,6 @@ class Members extends DolibarrApi
      *
      * @param   object  $object    Object to clean
      * @return    array    Array of cleaned object properties
-     *
-     * @todo use an array for properties to clean
-     *
      */
     function _cleanObjectDatas($object) {
 
diff --git a/htdocs/adherents/class/api_subscriptions.class.php b/htdocs/adherents/class/api_subscriptions.class.php
index 10f25e88e424e3c2caeff9168cb9fadc2351c0d1..1917e3b84edd2bd89986b0950eca46fb72e11c85 100644
--- a/htdocs/adherents/class/api_subscriptions.class.php
+++ b/htdocs/adherents/class/api_subscriptions.class.php
@@ -135,7 +135,7 @@ class Subscriptions extends DolibarrApi
             }
         }
         else {
-            throw new RestException(503, 'Error when retrieve subscription list : '.$subscription->error);
+            throw new RestException(503, 'Error when retrieve subscription list : '.$db->lasterror());
         }
         if( ! count($obj_ret)) {
             throw new RestException(404, 'No Subscription found');
diff --git a/htdocs/api/class/api.class.php b/htdocs/api/class/api.class.php
index 75c814860a3c4a04f6382c6ea9491edf77dc3782..5ffae225df1b92d3361d6ac066b58dd9907a1596 100644
--- a/htdocs/api/class/api.class.php
+++ b/htdocs/api/class/api.class.php
@@ -81,9 +81,6 @@ class DolibarrApi
      *
      * @param   object  $object	Object to clean
      * @return	array	Array of cleaned object properties
-     *
-     * @todo use an array for properties to clean
-     *
      */
     function _cleanObjectDatas($object) {
 
diff --git a/htdocs/api/class/api_dictionnarycountries.class.php b/htdocs/api/class/api_dictionnarycountries.class.php
index 9b7b409ef19b748ac495ce5f213245f6dbcd5587..ddb3e2474a9e6aca5b3a5726cf2d1b755295436d 100644
--- a/htdocs/api/class/api_dictionnarycountries.class.php
+++ b/htdocs/api/class/api_dictionnarycountries.class.php
@@ -54,7 +54,7 @@ class DictionnaryCountries extends DolibarrApi
      * @param int       $page       Page number (starting from zero)
      * @param string    $filter     To filter the countries by name
      * @param string    $lang       Code of the language the label of the countries must be translated to
-     * @param string    $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
+     * @param string    $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
      * @return List of countries
      *            
      * @throws RestException
diff --git a/htdocs/api/class/api_dictionnarytowns.class.php b/htdocs/api/class/api_dictionnarytowns.class.php
index b5813d077929b023b4a5a05421b18895be89397c..da58c9109eb86ab5d5188eca02b2e1fde3996937 100644
--- a/htdocs/api/class/api_dictionnarytowns.class.php
+++ b/htdocs/api/class/api_dictionnarytowns.class.php
@@ -47,7 +47,7 @@ class DictionnaryTowns extends DolibarrApi
      * @param int       $page       Page number (starting from zero)
      * @param string    $zipcode    To filter on zipcode
      * @param string    $town       To filter on city name
-     * @param string    $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
+     * @param string    $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
      * @return List of towns
      *            
      * @throws RestException
diff --git a/htdocs/api/index.php b/htdocs/api/index.php
index 99ad91adde9f5477d6c85b5a4df36598d6e5fd43..8ad60c4b340f48e58814903eb2ff866440acaa6b 100644
--- a/htdocs/api/index.php
+++ b/htdocs/api/index.php
@@ -115,6 +115,10 @@ foreach ($modulesdir as $dir)
                 elseif ($module == 'stock') {
                     $moduledirforclass = 'product/stock';
                 }
+                elseif ($module == 'fournisseur') {
+                    $moduledirforclass = 'fourn';
+                }
+                //dol_syslog("Found module file ".$file." - module=".$module." - moduledirforclass=".$moduledirforclass);
                 
                 // Defined if module is enabled
                 $enabled=true;
@@ -137,6 +141,8 @@ foreach ($modulesdir as $dir)
                     {
                         while (($file_searched = readdir($handle_part))!==false)
                         {
+                            if ($file_searched == 'api_access.class.php') continue;
+                            
                             // Support of the deprecated API.
                             if (is_readable($dir_part.$file_searched) && preg_match("/^api_deprecated_(.*)\.class\.php$/i",$file_searched,$reg))
                             {
@@ -144,19 +150,28 @@ foreach ($modulesdir as $dir)
                                 require_once $dir_part.$file_searched;
                                 if (class_exists($classname))
                                 {
-                                    dol_syslog("Found deprecated API by index.php: classname=".$classname." into ".$dir." - ".$dir_part.$file_searched);
+                                    //dol_syslog("Found deprecated API by index.php: classname=".$classname." for module ".$dir." into ".$dir_part.$file_searched);
                                     $api->r->addAPIClass($classname, '/');
                                 }
+                                else
+                                {
+                                    dol_syslog("We found an api_xxx file (".$file_searched.") but class ".$classname." does not exists after loading file", LOG_WARNING);
+                                }
                             }
                             elseif (is_readable($dir_part.$file_searched) && preg_match("/^api_(.*)\.class\.php$/i",$file_searched,$reg))
                             {
                                 $classname = ucwords($reg[1]);
+                                $classname = str_replace('_', '', $classname);
                                 require_once $dir_part.$file_searched;
                                 if (class_exists($classname))
                                 {
-                                    dol_syslog("Found API by index.php: classname=".$classname." into ".$dir." - ".$dir_part.$file_searched);
+                                    //dol_syslog("Found API by index.php: classname=".$classname." for module ".$dir." into ".$dir_part.$file_searched);
                                     $listofapis[] = $classname;
                                 }
+                                else
+                                {
+                                    dol_syslog("We found an api_xxx file (".$file_searched.") but class ".$classname." does not exists after loading file", LOG_WARNING);
+                                }
                             }
                         }
                     }
diff --git a/htdocs/categories/class/api_categories.class.php b/htdocs/categories/class/api_categories.class.php
index 471c6b2fdde2b450df7c931777b593e854b91db4..921198ab1beca82c747133137e8b930eb0411b10 100644
--- a/htdocs/categories/class/api_categories.class.php
+++ b/htdocs/categories/class/api_categories.class.php
@@ -157,7 +157,7 @@ class Categories extends DolibarrApi
             }
         }
         else {
-            throw new RestException(503, 'Error when retrieve category list : '.$category_static->error);
+            throw new RestException(503, 'Error when retrieve category list : '.$db->lasterror());
         }
         if( ! count($obj_ret)) {
             throw new RestException(404, 'No category found');
@@ -243,7 +243,7 @@ class Categories extends DolibarrApi
             }
         }
         else {
-            throw new RestException(503, 'Error when retrieve category list : '.$category_static->error);
+            throw new RestException(503, 'Error when retrieve category list : '.$db->lasterror());
         }
         if( ! count($obj_ret)) {
             throw new RestException(404, 'No category found');
@@ -346,9 +346,6 @@ class Categories extends DolibarrApi
      *
      * @param   Categorie  $object    Object to clean
      * @return    array    Array of cleaned object properties
-     *
-     * @todo use an array for properties to clean
-     *
      */
     function _cleanObjectDatas($object) {
     
diff --git a/htdocs/categories/class/api_deprecated_category.class.php b/htdocs/categories/class/api_deprecated_category.class.php
index 2cb25b70779400f0c99eb2c5c44f8f1fe3e49472..8ec125290c5f1592624aebe3d38c7d8519943a16 100644
--- a/htdocs/categories/class/api_deprecated_category.class.php
+++ b/htdocs/categories/class/api_deprecated_category.class.php
@@ -152,13 +152,13 @@ class CategoryApi extends DolibarrApi
                 $obj = $db->fetch_object($result);
                 $category_static = new Categorie($db);
                 if($category_static->fetch($obj->rowid)) {
-                    $obj_ret[] = parent::_cleanObjectDatas($category_static);
+                    $obj_ret[] = $this->_cleanObjectDatas($category_static);
                 }
                 $i++;
             }
         }
         else {
-            throw new RestException(503, 'Error when retrieve category list : '.$category_static->error);
+            throw new RestException(503, 'Error when retrieve category list : '.$db->lasterror());
         }
         if( ! count($obj_ret)) {
             throw new RestException(404, 'No category found');
@@ -233,13 +233,13 @@ class CategoryApi extends DolibarrApi
                 $obj = $db->fetch_object($result);
                 $category_static = new Categorie($db);
                 if($category_static->fetch($obj->rowid)) {
-                    $obj_ret[] = parent::_cleanObjectDatas($category_static);
+                    $obj_ret[] = $this->_cleanObjectDatas($category_static);
                 }
                 $i++;
             }
         }
         else {
-            throw new RestException(503, 'Error when retrieve category list : '.$category_static->error);
+            throw new RestException(503, 'Error when retrieve category list : '.$db->lasterror());
         }
         if( ! count($obj_ret)) {
             throw new RestException(404, 'No category found');
diff --git a/htdocs/comm/action/class/api_agendaevents.class.php b/htdocs/comm/action/class/api_agendaevents.class.php
index 3c2f84b4700a349e80d4596014783acf32398d97..931283b0ab0e22c33517b0f73b38dec2ee34e214 100644
--- a/htdocs/comm/action/class/api_agendaevents.class.php
+++ b/htdocs/comm/action/class/api_agendaevents.class.php
@@ -146,13 +146,13 @@ class AgendaEvents extends DolibarrApi
                 $obj = $db->fetch_object($result);
                 $actioncomm_static = new ActionComm($db);
                 if($actioncomm_static->fetch($obj->rowid)) {
-                    $obj_ret[] = parent::_cleanObjectDatas($actioncomm_static);
+                    $obj_ret[] = $this->_cleanObjectDatas($actioncomm_static);
                 }
                 $i++;
             }
         }
         else {
-            throw new RestException(503, 'Error when retrieve Agenda Event list');
+            throw new RestException(503, 'Error when retrieve Agenda Event list : '.$db->lasterror());
         }
         if( ! count($obj_ret)) {
             throw new RestException(404, 'No Agenda Event found');
diff --git a/htdocs/comm/index.php b/htdocs/comm/index.php
index ad2bf294e6b29c2b86d7a91e01ad7bdd9edb24b0..4e99b7072fc677617da8f75d9c94383bcc2f27e3 100644
--- a/htdocs/comm/index.php
+++ b/htdocs/comm/index.php
@@ -385,7 +385,7 @@ if (! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->commande
     if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
     $sql.= " WHERE cf.fk_soc = s.rowid";
     $sql.= " AND cf.fk_statut = 0";
-    $sql.= " AND cf.entity IN (".getEntity('commande_fournisseur', 1).")";
+    $sql.= " AND cf.entity IN (".getEntity('supplier_order', 1).")";
     if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
     if ($socid)	$sql.= " AND cf.fk_soc = ".$socid;
 
diff --git a/htdocs/comm/propal/class/api_proposals.class.php b/htdocs/comm/propal/class/api_proposals.class.php
index c1b223f6f289328e6f66c6ea4501325e374d4ba8..b4a15c2aa97b4dd2c09bec6d9d1a4a6a53cc10c2 100644
--- a/htdocs/comm/propal/class/api_proposals.class.php
+++ b/htdocs/comm/propal/class/api_proposals.class.php
@@ -150,13 +150,13 @@ class Proposals extends DolibarrApi
                 $obj = $db->fetch_object($result);
                 $propal_static = new Propal($db);
                 if($propal_static->fetch($obj->rowid)) {
-                    $obj_ret[] = parent::_cleanObjectDatas($propal_static);
+                    $obj_ret[] = $this->_cleanObjectDatas($propal_static);
                 }
                 $i++;
             }
         }
         else {
-            throw new RestException(503, 'Error when retrieve propal list');
+            throw new RestException(503, 'Error when retrieve propal list : '.$db->lasterror());
         }
         if( ! count($obj_ret)) {
             throw new RestException(404, 'No order found');
diff --git a/htdocs/commande/class/api_deprecated_commande.class.php b/htdocs/commande/class/api_deprecated_commande.class.php
index b0b22764ec76da397ebdd418afd8b218b3bbe332..f5d799dd477022455a158484b90ff018630e25eb 100644
--- a/htdocs/commande/class/api_deprecated_commande.class.php
+++ b/htdocs/commande/class/api_deprecated_commande.class.php
@@ -167,13 +167,13 @@ class CommandeApi extends DolibarrApi
                 $obj = $db->fetch_object($result);
                 $commande_static = new Commande($db);
                 if($commande_static->fetch($obj->rowid)) {
-                    $obj_ret[] = parent::_cleanObjectDatas($commande_static);
+                    $obj_ret[] = $this->_cleanObjectDatas($commande_static);
                 }
                 $i++;
             }
         }
         else {
-            throw new RestException(503, 'Error when retrieve commande list');
+            throw new RestException(503, 'Error when retrieve commande list : '.$db->lasterror());
         }
         if( ! count($obj_ret)) {
             throw new RestException(404, 'No commande found');
diff --git a/htdocs/commande/class/api_orders.class.php b/htdocs/commande/class/api_orders.class.php
index 646e9ead2703eb165688936e84b2399089e58405..cc186367588c5aac8601afb12998925df479e44c 100644
--- a/htdocs/commande/class/api_orders.class.php
+++ b/htdocs/commande/class/api_orders.class.php
@@ -94,6 +94,8 @@ class Orders extends DolibarrApi
      * @param string   	       $thirdparty_ids	    Thirdparty ids to filter orders of. {@example '1' or '1,2,3'} {@pattern /^[0-9,]*$/i}
      * @param string           $sqlfilters          Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
      * @return  array                               Array of order objects
+     *
+	 * @throws RestException
      */
     function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '') {
         global $db, $conf;
@@ -153,13 +155,13 @@ class Orders extends DolibarrApi
                 $obj = $db->fetch_object($result);
                 $commande_static = new Commande($db);
                 if($commande_static->fetch($obj->rowid)) {
-                    $obj_ret[] = parent::_cleanObjectDatas($commande_static);
+                    $obj_ret[] = $this->_cleanObjectDatas($commande_static);
                 }
                 $i++;
             }
         }
         else {
-            throw new RestException(503, 'Error when retrieve commande list');
+            throw new RestException(503, 'Error when retrieve commande list : '.$db->lasterror());
         }
         if( ! count($obj_ret)) {
             throw new RestException(404, 'No order found');
diff --git a/htdocs/compta/facture/class/api_deprecated_invoice.class.php b/htdocs/compta/facture/class/api_deprecated_invoice.class.php
index a2706b3150fc55063668df44826a885cbf1eb3bb..b87bb2e9dc0dc3bd91b9d22a996c8c33922a1b29 100644
--- a/htdocs/compta/facture/class/api_deprecated_invoice.class.php
+++ b/htdocs/compta/facture/class/api_deprecated_invoice.class.php
@@ -165,13 +165,13 @@ class InvoiceApi extends DolibarrApi
                 $obj = $db->fetch_object($result);
                 $invoice_static = new Facture($db);
                 if($invoice_static->fetch($obj->rowid)) {
-                    $obj_ret[] = parent::_cleanObjectDatas($invoice_static);
+                    $obj_ret[] = $this->_cleanObjectDatas($invoice_static);
                 }
                 $i++;
             }
         }
         else {
-            throw new RestException(503, 'Error when retrieve invoice list');
+            throw new RestException(503, 'Error when retrieve invoice list : '.$db->lasterror());
         }
         if( ! count($obj_ret)) {
             throw new RestException(404, 'No invoice found');
diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php
index e0a2e12695a298c1d3b3dc3a641bb203db8f3fa7..888c05bff264c2d0cc6576009a22ef5efced5ebe 100644
--- a/htdocs/compta/facture/class/api_invoices.class.php
+++ b/htdocs/compta/facture/class/api_invoices.class.php
@@ -83,23 +83,23 @@ class Invoices extends DolibarrApi
      * 
      * Get a list of invoices
      * 
-     * @param string	$sortfield	Sort field
-     * @param string	$sortorder	Sort order
-     * @param int		$limit		Limit for list
-     * @param int		$page		Page number
-     * @param int       $socid      Filter list with thirdparty ID
-     * @param string	$status		Filter by invoice status : draft | unpaid | paid | cancelled
-     * @param string    $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
-     * @return array                Array of invoice objects
+     * @param string	$sortfield	      Sort field
+     * @param string	$sortorder	      Sort order
+     * @param int		$limit		      Limit for list
+     * @param int		$page		      Page number
+     * @param string   	$thirdparty_ids	  Thirdparty ids to filter orders of. {@example '1' or '1,2,3'} {@pattern /^[0-9,]*$/i}
+     * @param string	$status		      Filter by invoice status : draft | unpaid | paid | cancelled
+     * @param string    $sqlfilters       Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
+     * @return array                      Array of invoice objects
      *
 	 * @throws RestException
      */
-    function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $socid=0, $status='', $sqlfilters = '') {
+    function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $thirdparty_ids='', $status='', $sqlfilters = '') {
         global $db, $conf;
         
         $obj_ret = array();
-        
-        $socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : $socid;
+        // case of external user, $thirdpartyid param is ignored and replaced by user's socid
+        $socids = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : $thirdparty_ids;
             
         // If the internal user must only see his customers, force searching by him
         if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id;
@@ -112,7 +112,7 @@ class Invoices extends DolibarrApi
 
         $sql.= ' WHERE t.entity IN ('.getEntity('facture', 1).')';
         if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= " AND t.fk_soc = sc.fk_soc";
-        if ($socid) $sql.= " AND t.fk_soc = ".$socid;
+        if ($socids) $sql.= " AND t.fk_soc IN (".$socids.")";
         if ($search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc";		// Join for the needed table to filter by sale
         
 		// Filter by status
@@ -156,13 +156,13 @@ class Invoices extends DolibarrApi
                 $obj = $db->fetch_object($result);
                 $invoice_static = new Facture($db);
                 if($invoice_static->fetch($obj->rowid)) {
-                    $obj_ret[] = parent::_cleanObjectDatas($invoice_static);
+                    $obj_ret[] = $this->_cleanObjectDatas($invoice_static);
                 }
                 $i++;
             }
         }
         else {
-            throw new RestException(503, 'Error when retrieve invoice list');
+            throw new RestException(503, 'Error when retrieve invoice list : '.$db->lasterror());
         }
         if( ! count($obj_ret)) {
             throw new RestException(404, 'No invoice found');
@@ -255,7 +255,7 @@ class Invoices extends DolibarrApi
             throw new RestException(404, 'Invoice not found');
         }
 		
-		if( ! DolibarrApi::_checkAccessToResource('facture',$this->facture->id)) {
+		if( ! DolibarrApi::_checkAccessToResource('facture',$this->invoice->id)) {
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
 		}
         
@@ -267,7 +267,7 @@ class Invoices extends DolibarrApi
          return array(
             'success' => array(
                 'code' => 200,
-                'message' => 'Facture deleted'
+                'message' => 'Invoice deleted'
             )
         );
     }
diff --git a/htdocs/core/modules/modFournisseur.class.php b/htdocs/core/modules/modFournisseur.class.php
index c0203f7e49066171bdd04640af137c028ebc3db5..2999bddd1bd2ac6aedde1ab603e55c838fd65697 100644
--- a/htdocs/core/modules/modFournisseur.class.php
+++ b/htdocs/core/modules/modFournisseur.class.php
@@ -380,7 +380,7 @@ class modFournisseur extends DolibarrModules
 		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_det_extrafields as extraline ON fd.rowid = extraline.fk_object';
 		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
 		$this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture_fourn';
-		$this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('facture_fournisseur',1).')';
+		$this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('supplier_invoice',1).')';
 		if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id;
 
 		$r++;
@@ -443,7 +443,7 @@ class modFournisseur extends DolibarrModules
 		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid';
 		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn as p ON pf.fk_paiementfourn = p.rowid';
 		$this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid';
-        $this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('facture_fournisseur',1).')';
+        $this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('supplier_invoice',1).')';
 		if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id;
 
 		// Order
@@ -552,7 +552,7 @@ class modFournisseur extends DolibarrModules
 		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'commande_fournisseurdet_extrafields as extraline ON fd.rowid = extraline.fk_object';
 		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
 		$this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_commande';
-		$this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('commande_fournisseur',1).')';
+		$this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('supplier_order',1).')';
 		if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id;
 	}
 
diff --git a/htdocs/expensereport/class/api_expensereports.class.php b/htdocs/expensereport/class/api_expensereports.class.php
index ce7ce544f12ccc11cd4e1743610167582cf6f4ae..bf07089b71b7440545bf6549b2768f41ad64f82d 100644
--- a/htdocs/expensereport/class/api_expensereports.class.php
+++ b/htdocs/expensereport/class/api_expensereports.class.php
@@ -144,13 +144,13 @@ class ExpenseReports extends DolibarrApi
                 $obj = $db->fetch_object($result);
                 $expensereport_static = new ExpenseReport($db);
                 if($expensereport_static->fetch($obj->rowid)) {
-                    $obj_ret[] = parent::_cleanObjectDatas($expensereport_static);
+                    $obj_ret[] = $this->_cleanObjectDatas($expensereport_static);
                 }
                 $i++;
             }
         }
         else {
-            throw new RestException(503, 'Error when retrieve Expense Report list');
+            throw new RestException(503, 'Error when retrieve Expense Report list : '.$db->lasterror());
         }
         if( ! count($obj_ret)) {
             throw new RestException(404, 'No Expense Report found');
diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php
index af7bec526a684b3ef02337362c2302c13ebc73d3..878c0886918456d2a3215d4494d2c09f132e51e7 100644
--- a/htdocs/fourn/class/fournisseur.facture.class.php
+++ b/htdocs/fourn/class/fournisseur.facture.class.php
@@ -208,7 +208,7 @@ class FactureFournisseur extends CommonInvoice
      *    Create supplier invoice into database
      *
      *    @param      User		$user       object utilisateur qui cree
-     *    @return     int    	     		id facture si ok, < 0 si erreur
+     *    @return     int    	     		Id invoice created if OK, < 0 if KO
      */
     public function create($user)
     {
@@ -313,32 +313,84 @@ class FactureFournisseur extends CommonInvoice
                 }
             }
 
-            foreach ($this->lines as $i => $val)
-            {
-                $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facture_fourn_det (fk_facture_fourn)';
-                $sql .= ' VALUES ('.$this->id.');';
-
-                dol_syslog(get_class($this)."::create", LOG_DEBUG);
-                $resql_insert=$this->db->query($sql);
-                if ($resql_insert)
+			if (count($this->lines) && is_object($this->lines[0]))	// If this->lines is array of InvoiceLines (preferred mode)
+			{
+                dol_syslog("There is ".count($this->lines)." lines that are invoice lines objects");
+                foreach ($this->lines as $i => $val)
                 {
-                    $idligne = $this->db->last_insert_id(MAIN_DB_PREFIX.'facture_fourn_det');
-
-                    $this->updateline(
-                        $idligne,
-                        $this->lines[$i]->description,
-                        $this->lines[$i]->pu_ht,
-                        $this->lines[$i]->tva_tx,
-                        $this->lines[$i]->localtax1_tx,
-                        $this->lines[$i]->localtax2_tx,
-                        $this->lines[$i]->qty,
-                        $this->lines[$i]->fk_product,
-                        'HT',
-                        (! empty($this->lines[$i]->info_bits)?$this->lines[$i]->info_bits:''),
-                        $this->lines[$i]->product_type
-                    );
+                    $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facture_fourn_det (fk_facture_fourn)';
+                    $sql .= ' VALUES ('.$this->id.')';
+    
+                    $resql_insert=$this->db->query($sql);
+                    if ($resql_insert)
+                    {
+                        $idligne = $this->db->last_insert_id(MAIN_DB_PREFIX.'facture_fourn_det');
+    
+                        var_dump($this->lines[$i]);exit;
+                        $this->updateline(
+                            $idligne,
+                            $this->lines[$i]->description,
+                            $this->lines[$i]->pu_ht,
+                            $this->lines[$i]->tva_tx,
+                            $this->lines[$i]->localtax1_tx,
+                            $this->lines[$i]->localtax2_tx,
+                            $this->lines[$i]->qty,
+                            $this->lines[$i]->fk_product,
+                            'HT',
+                            (! empty($this->lines[$i]->info_bits)?$this->lines[$i]->info_bits:''),
+                            $this->lines[$i]->product_type
+                        );
+                    }
+                    else
+                    {
+                        $this->error=$this->db->lasterror();
+                        $this->db->rollback();
+                        return -5;
+                    }
                 }
-            }
+			}
+			else	// If this->lines is an array of invoice line arrays
+			{
+			    dol_syslog("There is ".count($this->lines)." lines that are array lines");
+			    foreach ($this->lines as $i => $val)
+			    {
+                	$line = $this->lines[$i];
+                	
+                	// Test and convert into object this->lines[$i]. When coming from REST API, we may still have an array
+				    //if (! is_object($line)) $line=json_decode(json_encode($line), FALSE);  // convert recursively array into object.
+                	if (! is_object($line)) $line = (object) $line;
+			        
+                	$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facture_fourn_det (fk_facture_fourn)';
+			        $sql .= ' VALUES ('.$this->id.')';
+			    
+			        $resql_insert=$this->db->query($sql);
+			        if ($resql_insert)
+			        {
+			            $idligne = $this->db->last_insert_id(MAIN_DB_PREFIX.'facture_fourn_det');
+			    
+			            $this->updateline(
+			                $idligne,
+			                $line->description,
+			                $line->pu_ht,
+			                $line->tva_tx,
+			                $line->localtax1_tx,
+			                $line->localtax2_tx,
+			                $line->qty,
+			                $line->fk_product,
+			                'HT',
+			                (! empty($line->info_bits)?$line->info_bits:''),
+			                $line->product_type
+			                );
+			        }
+			        else
+			        {
+			            $this->error=$this->db->lasterror();
+			            $this->db->rollback();
+			            return -5;
+			        }
+			    }			    
+			}
+			
             // Update total price
             $result=$this->update_price();
             if ($result > 0)
diff --git a/htdocs/fourn/commande/list.php b/htdocs/fourn/commande/list.php
index 706ca4e143f3ba1388e6caa1dbe086c7eb3c9a14..97153d94e2f0e0c3e48396ecf0ee85a07e28186d 100644
--- a/htdocs/fourn/commande/list.php
+++ b/htdocs/fourn/commande/list.php
@@ -293,7 +293,7 @@ if ($search_user > 0)
     $sql.=", ".MAIN_DB_PREFIX."c_type_contact as tc";
 }
 $sql.= ' WHERE cf.fk_soc = s.rowid';
-$sql.= ' AND cf.entity IN ('.getEntity('commande_fournisseur', 1).')';
+$sql.= ' AND cf.entity IN ('.getEntity('supplier_order', 1).')';
 if ($socid > 0) $sql.= " AND s.rowid = ".$socid;
 if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 if ($search_ref) $sql .= natural_search('cf.ref', $search_ref);
diff --git a/htdocs/fourn/facture/list.php b/htdocs/fourn/facture/list.php
index 84b91bd3a27f2a6c17f584de6d1a10f235d25ac7..a66e624619ca9f922bf44787d41025e1d9567292 100644
--- a/htdocs/fourn/facture/list.php
+++ b/htdocs/fourn/facture/list.php
@@ -248,7 +248,7 @@ llxHeader('',$langs->trans("SuppliersInvoices"),'EN:Suppliers_Invoices|FR:Factur
 $sql = "SELECT";
 if ($search_all || $search_product_category > 0) $sql = 'SELECT DISTINCT';
 $sql.= " f.rowid as facid, f.ref, f.ref_supplier, f.datef, f.date_lim_reglement as datelimite, f.fk_mode_reglement,";
-$sql.= " f.total_ht, f.total_ttc, f.total_tva as total_vat, f.paye as paye, f.fk_statut as fk_statut, f.libelle as label,";
+$sql.= " f.total_ht, f.total_ttc, f.total_tva as total_vat, f.paye as paye, f.fk_statut as fk_statut, f.libelle as label, f.datec as date_creation, f.tms as date_update,";
 $sql.= " s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client,";
 $sql.= " typent.code as typent_code,";
 $sql.= " state.code_departement as state_code, state.nom as state_name,";
diff --git a/htdocs/product/class/api_deprecated_product.class.php b/htdocs/product/class/api_deprecated_product.class.php
index cdda0c45fbb7cafe07c4e778ab2740182885d6f2..938e591226f7924d98fbc6ab2c37abd3a5dc284d 100644
--- a/htdocs/product/class/api_deprecated_product.class.php
+++ b/htdocs/product/class/api_deprecated_product.class.php
@@ -154,13 +154,13 @@ class ProductApi extends DolibarrApi
                 $obj = $db->fetch_object($result);
                 $product_static = new Product($db);
                 if($product_static->fetch($obj->rowid)) {
-                    $obj_ret[] = parent::_cleanObjectDatas($product_static);
+                    $obj_ret[] = $this->_cleanObjectDatas($product_static);
                 }
                 $i++;
             }
         }
         else {
-            throw new RestException(503, 'Error when retrieve product list');
+            throw new RestException(503, 'Error when retrieve product list : '.$db->lasterror());
         }
         if( ! count($obj_ret)) {
             throw new RestException(404, 'No product found');
@@ -240,13 +240,13 @@ class ProductApi extends DolibarrApi
                 $obj = $db->fetch_object($result);
                 $product_static = new Product($db);
                 if($product_static->fetch($obj->rowid)) {
-                    $obj_ret[] = parent::_cleanObjectDatas($product_static);
+                    $obj_ret[] = $this->_cleanObjectDatas($product_static);
                 }
                 $i++;
             }
         }
         else {
-            throw new RestException(503, 'Error when retrieve product list');
+            throw new RestException(503, 'Error when retrieve product list : '.$db->lasterror());
         }
         if( ! count($obj_ret)) {
             throw new RestException(404, 'No product found');
diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php
index 0c08fb0dc35a34cf358284b1d244a254918e39fc..19fae0b6342a0e22eab7542198bf7369303354aa 100644
--- a/htdocs/product/class/api_products.class.php
+++ b/htdocs/product/class/api_products.class.php
@@ -151,13 +151,13 @@ class Products extends DolibarrApi
                 $obj = $db->fetch_object($result);
                 $product_static = new Product($db);
                 if($product_static->fetch($obj->rowid)) {
-                    $obj_ret[] = parent::_cleanObjectDatas($product_static);
+                    $obj_ret[] = $this->_cleanObjectDatas($product_static);
                 }
                 $i++;
             }
         }
         else {
-            throw new RestException(503, 'Error when retrieve product list');
+            throw new RestException(503, 'Error when retrieve product list : '.$db->lasterror());
         }
         if( ! count($obj_ret)) {
             throw new RestException(404, 'No product found');
diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php
index bb122dc70e83ade8fd8d283c56e2ea5fde3559f1..46da76a5f57ab7cb01179ec4f5d6a55dda8b2b0a 100644
--- a/htdocs/product/class/product.class.php
+++ b/htdocs/product/class/product.class.php
@@ -2054,7 +2054,7 @@ class Product extends CommonObject
 		if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
 		$sql.= " WHERE c.rowid = cd.fk_commande";
 		$sql.= " AND c.fk_soc = s.rowid";
-		$sql.= " AND c.entity IN (".getEntity('commande_fournisseur', 1).")";
+		$sql.= " AND c.entity IN (".getEntity('supplier_order', 1).")";
 		$sql.= " AND cd.fk_product = ".$this->id;
 		if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
 		if ($socid > 0) $sql.= " AND c.fk_soc = ".$socid;
@@ -2142,7 +2142,7 @@ class Product extends CommonObject
 		if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
 		$sql.= " WHERE cf.rowid = fd.fk_commande";
 		$sql.= " AND cf.fk_soc = s.rowid";
-		$sql.= " AND cf.entity IN (".getEntity('commande_fournisseur', 1).")";
+		$sql.= " AND cf.entity IN (".getEntity('supplier_order', 1).")";
 		$sql.= " AND fd.fk_product = ".$this->id;
 		if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND cf.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
 		if ($socid > 0)	$sql.= " AND cf.fk_soc = ".$socid;
@@ -2530,7 +2530,7 @@ class Product extends CommonObject
 		else $sql.=" AND d.fk_product > 0";
 		if ($filteronproducttype >= 0) $sql.= " AND p.rowid = d.fk_product AND p.fk_product_type =".$filteronproducttype;
 		$sql.= " AND c.fk_soc = s.rowid";
-		$sql.= " AND c.entity IN (".getEntity('commande_fournisseur', 1).")";
+		$sql.= " AND c.entity IN (".getEntity('supplier_order', 1).")";
 		if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
 		if ($socid > 0)	$sql.= " AND c.fk_soc = ".$socid;
 		$sql.= " GROUP BY date_format(c.date_commande,'%Y%m')";
diff --git a/htdocs/product/stock/class/api_stockmovements.class.php b/htdocs/product/stock/class/api_stockmovements.class.php
index a246e7fc135e0906c1fc7985d369bab3817aa4fb..677d34d9fcb76af1a62f7839e7c33ff18b48c053 100644
--- a/htdocs/product/stock/class/api_stockmovements.class.php
+++ b/htdocs/product/stock/class/api_stockmovements.class.php
@@ -144,7 +144,7 @@ class StockMovements extends DolibarrApi
             }
         }
         else {
-            throw new RestException(503, 'Error when retrieve stock movement list : '.$stockmovement_static->error);
+            throw new RestException(503, 'Error when retrieve stock movement list : '.$db->lasterror());
         }
         if( ! count($obj_ret)) {
             throw new RestException(404, 'No stock movement found');
@@ -277,9 +277,6 @@ class StockMovements extends DolibarrApi
      *
      * @param   MouvementStock  $object    Object to clean
      * @return    array    Array of cleaned object properties
-     *
-     * @todo use an array for properties to clean
-     *
      */
     function _cleanObjectDatas($object) {
     
diff --git a/htdocs/product/stock/class/api_warehouses.class.php b/htdocs/product/stock/class/api_warehouses.class.php
index 79eefc821c3836241cef0c79e9b5281ddf62119e..d19918f0789e4ff1d1d204b40dbf098646388278 100644
--- a/htdocs/product/stock/class/api_warehouses.class.php
+++ b/htdocs/product/stock/class/api_warehouses.class.php
@@ -142,7 +142,7 @@ class Warehouses extends DolibarrApi
             }
         }
         else {
-            throw new RestException(503, 'Error when retrieve warehouse list : '.$warehouse_static->error);
+            throw new RestException(503, 'Error when retrieve warehouse list : '.$db->lasterror());
         }
         if( ! count($obj_ret)) {
             throw new RestException(404, 'No warehouse found');
@@ -246,9 +246,6 @@ class Warehouses extends DolibarrApi
      *
      * @param   Entrepot  $object    Object to clean
      * @return    array    Array of cleaned object properties
-     *
-     * @todo use an array for properties to clean
-     *
      */
     function _cleanObjectDatas($object) {
     
diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php
index 5281d913d95e0ac1fde42bb03dcda6c299c777ff..bb755868f24b0bf47e1fc0a9581839167f789945 100644
--- a/htdocs/product/stock/replenish.php
+++ b/htdocs/product/stock/replenish.php
@@ -352,14 +352,14 @@ if ($usevirtualstock)
 	$sqlCommandesFourn.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd";
 	$sqlCommandesFourn.= ", ".MAIN_DB_PREFIX."commande_fournisseur as c";
 	$sqlCommandesFourn.= " WHERE c.rowid = cd.fk_commande";
-	$sqlCommandesFourn.= " AND c.entity IN (".getEntity('commande_fournisseur', 1).")";
+	$sqlCommandesFourn.= " AND c.entity IN (".getEntity('supplier_order', 1).")";
 	$sqlCommandesFourn.= " AND cd.fk_product = p.rowid";
 	$sqlCommandesFourn.= " AND c.fk_statut IN (3,4))";
 
 	$sqlReceptionFourn = "(SELECT ".$db->ifsql("SUM(fd.qty) IS NULL", "0", "SUM(fd.qty)")." as qty";
 	$sqlReceptionFourn.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as cf";
 	$sqlReceptionFourn.= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as fd ON (fd.fk_commande = cf.rowid)";
-	$sqlReceptionFourn.= " WHERE cf.entity IN (".getEntity('commande_fournisseur', 1).")";
+	$sqlReceptionFourn.= " WHERE cf.entity IN (".getEntity('supplier_order', 1).")";
 	$sqlReceptionFourn.= " AND fd.fk_product = p.rowid";
 	$sqlReceptionFourn.= " AND cf.fk_statut IN (3,4))";
 
diff --git a/htdocs/projet/class/api_projects.class.php b/htdocs/projet/class/api_projects.class.php
index f36df0773eb8534df82f7aa1d67ac58362e42c19..2b5ee92d878c2fc89e70b5e4031f6d58afd6a848 100644
--- a/htdocs/projet/class/api_projects.class.php
+++ b/htdocs/projet/class/api_projects.class.php
@@ -162,7 +162,7 @@ class Projects extends DolibarrApi
             }
         }
         else {
-            throw new RestException(503, 'Error when retrieve project list');
+            throw new RestException(503, 'Error when retrieve project list : '.$db->lasterror());
         }
         if( ! count($obj_ret)) {
             throw new RestException(404, 'No project found');
@@ -531,9 +531,6 @@ class Projects extends DolibarrApi
      *
      * @param   object  $object    Object to clean
      * @return    array    Array of cleaned object properties
-     *
-     * @todo use an array for properties to clean
-     *
      */
     function _cleanObjectDatas($object) {
     
diff --git a/htdocs/projet/class/api_tasks.class.php b/htdocs/projet/class/api_tasks.class.php
index a5bab614a4a4a43073844cec150989630faf8c64..c88850ca403f481e7201f2ebaff238a3ba92a8f6 100644
--- a/htdocs/projet/class/api_tasks.class.php
+++ b/htdocs/projet/class/api_tasks.class.php
@@ -169,7 +169,7 @@ class Tasks extends DolibarrApi
             }
         }
         else {
-            throw new RestException(503, 'Error when retrieve task list');
+            throw new RestException(503, 'Error when retrieve task list : '.$db->lasterror());
         }
         if( ! count($obj_ret)) {
             throw new RestException(404, 'No task found');
@@ -544,9 +544,6 @@ class Tasks extends DolibarrApi
      *
      * @param   object  $object    Object to clean
      * @return    array    Array of cleaned object properties
-     *
-     * @todo use an array for properties to clean
-     *
      */
     function _cleanObjectDatas($object) {
     
diff --git a/htdocs/societe/class/api_contacts.class.php b/htdocs/societe/class/api_contacts.class.php
index 775d9d48cf470b2f2119d93af3e74ce1e561e346..9f09f7f740852cfe5d76ef753a1c5da79b54d0cf 100644
--- a/htdocs/societe/class/api_contacts.class.php
+++ b/htdocs/societe/class/api_contacts.class.php
@@ -160,7 +160,7 @@ class Contacts extends DolibarrApi
 				$contact_static = new Contact($db);
 				if ($contact_static->fetch($obj->rowid))
 				{
-					$obj_ret[] = parent::_cleanObjectDatas($contact_static);
+					$obj_ret[] = $this->_cleanObjectDatas($contact_static);
 				}
 				$i++;
 			}
diff --git a/htdocs/societe/class/api_deprecated_contact.class.php b/htdocs/societe/class/api_deprecated_contact.class.php
index d3d085e7135ddfecaf6920d7a147cb3c41ca1403..e229dc5f79bbc8cadbc8bfdc4419daef0314d16f 100644
--- a/htdocs/societe/class/api_deprecated_contact.class.php
+++ b/htdocs/societe/class/api_deprecated_contact.class.php
@@ -173,7 +173,7 @@ class ContactApi extends DolibarrApi
 				$contact_static = new Contact($db);
 				if ($contact_static->fetch($obj->rowid))
 				{
-					$obj_ret[] = parent::_cleanObjectDatas($contact_static);
+					$obj_ret[] = $this->_cleanObjectDatas($contact_static);
 				}
 				$i++;
 			}
diff --git a/htdocs/societe/class/api_deprecated_thirdparty.class.php b/htdocs/societe/class/api_deprecated_thirdparty.class.php
index 3e937557941418482fbb7ca3e4b0ff6015101e98..6086f2366d8358040cd435ee7a3ffc0d36183aec 100644
--- a/htdocs/societe/class/api_deprecated_thirdparty.class.php
+++ b/htdocs/societe/class/api_deprecated_thirdparty.class.php
@@ -218,13 +218,13 @@ class ThirdpartyApi extends DolibarrApi
                 $obj = $db->fetch_object($result);
                 $soc_static = new Societe($db);
                 if($soc_static->fetch($obj->rowid)) {
-                    $obj_ret[] = parent::_cleanObjectDatas($soc_static);
+                    $obj_ret[] = $this->_cleanObjectDatas($soc_static);
                 }
                 $i++;
             }
         }
         else {
-            throw new RestException(503, 'Error when retrieve thirdparties : ' . $sql);
+            throw new RestException(503, 'Error when retrieve thirdparties : '.$db->lasterror());
         }
         if( ! count($obj_ret)) {
             throw new RestException(404, 'Thirdparties not found');
diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php
index 13f28aea7050fae8a479ba248874b84f0af67a7c..bc156b5cc4a7c17271e4886789cf7c798c50a950 100644
--- a/htdocs/societe/class/api_thirdparties.class.php
+++ b/htdocs/societe/class/api_thirdparties.class.php
@@ -159,13 +159,13 @@ class Thirdparties extends DolibarrApi
                 $obj = $db->fetch_object($result);
                 $soc_static = new Societe($db);
                 if($soc_static->fetch($obj->rowid)) {
-                    $obj_ret[] = parent::_cleanObjectDatas($soc_static);
+                    $obj_ret[] = $this->_cleanObjectDatas($soc_static);
                 }
                 $i++;
             }
         }
         else {
-            throw new RestException(503, 'Error when retrieve thirdparties : ' . $sql);
+            throw new RestException(503, 'Error when retrieve thirdparties : '.$db->lasterror());
         }
         if( ! count($obj_ret)) {
             throw new RestException(404, 'Thirdparties not found');
diff --git a/htdocs/user/class/api_users.class.php b/htdocs/user/class/api_users.class.php
index db18bea229ab8e9f63cd02bde85fd1bbfaa1865f..3fc44104628fb0621b13cc718409def1e3020834 100644
--- a/htdocs/user/class/api_users.class.php
+++ b/htdocs/user/class/api_users.class.php
@@ -111,13 +111,13 @@ class Users extends DolibarrApi
 	            $obj = $db->fetch_object($result);
 	            $user_static = new User($db);
 	            if($user_static->fetch($obj->rowid)) {
-	                $obj_ret[] = parent::_cleanObjectDatas($user_static);
+	                $obj_ret[] = $this->_cleanObjectDatas($user_static);
 	            }
 	            $i++;
 	        }
 	    }
 	    else {
-	        throw new RestException(503, 'Error when retrieve User list');
+	        throw new RestException(503, 'Error when retrieve User list : '.$db->lasterror());
 	    }
 	    if( ! count($obj_ret)) {
 	        throw new RestException(404, 'No User found');