diff --git a/htdocs/societe/class/api_contacts.class.php b/htdocs/societe/class/api_contacts.class.php index 7f24713913f..38e6bb59ef4 100644 --- a/htdocs/societe/class/api_contacts.class.php +++ b/htdocs/societe/class/api_contacts.class.php @@ -61,12 +61,13 @@ class Contacts extends DolibarrApi * * Return an array with contact informations * - * @param int $id ID of contact + * @param int $id ID of contact + * @param int $includecount Count and return also number of elements the contact is used as a link for * @return array|mixed data without useless information * * @throws RestException */ - function get($id) + function get($id, $includecount = 0) { if (!DolibarrApiAccess::$user->rights->societe->contact->lire) { @@ -74,7 +75,7 @@ class Contacts extends DolibarrApi } $result = $this->contact->fetch($id); - $this->contact->load_ref_elements(); + if (!$result) { throw new RestException(404, 'Contact not found'); @@ -85,6 +86,11 @@ class Contacts extends DolibarrApi throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login); } + if ($includecount) + { + $this->contact->load_ref_elements(); + } + return $this->_cleanObjectDatas($this->contact); }