From e77b470cad253fbacffbf76af25a4c2f4bd9db98 Mon Sep 17 00:00:00 2001 From: Thibault Parodi <53296763+tpi7@users.noreply.github.com> Date: Fri, 2 May 2025 22:44:48 +0200 Subject: [PATCH] NEW: Add an API endpoint to get properties of a single line of an order (#34045) * feat: add api get line properties route * chore: indent with tabs * chore: preserve original spaces * chore: tabs instead of space * fix: return Object instead of array --- htdocs/commande/class/api_orders.class.php | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/htdocs/commande/class/api_orders.class.php b/htdocs/commande/class/api_orders.class.php index 69f467d2b51..6ed73c8348a 100644 --- a/htdocs/commande/class/api_orders.class.php +++ b/htdocs/commande/class/api_orders.class.php @@ -363,6 +363,41 @@ class Orders extends DolibarrApi return $result; } + /** + * Get properties of a line of an order object by id + * + * @param int $id Id of order + * @param int $lineid Id of line + * @param string $properties Restrict the data returned to these properties. Ignored if empty. Comma separated list of properties names + * + * @url GET {id}/lines/{lineid} + * + * @return Object + */ + public function getLine($id, $lineid, $properties = '') + { + if (!DolibarrApiAccess::$user->hasRight('commande', 'lire')) { + throw new RestException(403); + } + + $result = $this->commande->fetch($id); + if (!$result) { + throw new RestException(404, 'Order not found'); + } + + if (!DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) { + throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $this->commande->fetch_lines(); + foreach ($this->commande->lines as $line) { + if ($line->id == $lineid) { + return $this->_filterObjectProperties($this->_cleanObjectDatas($line), $properties); + } + } + throw new RestException(404, 'Line not found'); + } + /** * Add a line to given order *