From 0c2f6ea9b04e86eb6e1e7e7b204ca470e220aecb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charl=C3=A8ne=20Benke?= <1179011+defrance@users.noreply.github.com> Date: Tue, 7 Oct 2025 20:51:07 +0200 Subject: [PATCH] add getContacts method on invoice api (#35656) * add getContacts method on invoice api Add the getContacts method to fetch both external and internal contacts for a given invoice. * Change return type from Object to array in API docs Updated return type in the documentation for the get contacts method. * Update api_invoices.class.php --------- Co-authored-by: Laurent Destailleur --- .../facture/class/api_invoices.class.php | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index 8d6eb7a46f2..e79ef595a41 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -4,6 +4,7 @@ * Copyright (C) 2023 Joachim Kueter * Copyright (C) 2024-2025 Frédéric France * Copyright (C) 2024-2025 MDW + * Copyright (C) 2025 Charlene Benke * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -621,6 +622,42 @@ class Invoices extends DolibarrApi ); } + /** + * Get contacts of given invoice + * + * Return an array with contact information + * + * @param int $id ID of invoice + * @param string $type Type of the contact (BILLING, SHIPPING, CUSTOMER) + * @return array Array with contact and user associated + * + * @url GET {id}/contacts + * + * @throws RestException + */ + public function getContacts($id, $type = '') + { + if (!DolibarrApiAccess::$user->hasRight('facture', 'lire')) { + throw new RestException(403); + } + + $result = $this->invoice->fetch($id); + if (!$result) { + throw new RestException(404, 'Invoice not found'); + } + + if (!DolibarrApi::_checkAccessToResource('facture', $this->invoice->id)) { + throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $contacts = $this->invoice->liste_contact(-1, 'external', 0, $type); + $socpeoples = $this->invoice->liste_contact(-1, 'internal', 0, $type); + + $contacts = array_merge($contacts, $socpeoples); + + return $contacts; + } + /** * Delete a contact type of given invoice *