From 6049574af77eeb8441ffc4fefcb4d9ec00db5b86 Mon Sep 17 00:00:00 2001 From: Pichinov-Jose Date: Tue, 4 Aug 2026 18:36:51 +0200 Subject: [PATCH] Ticket API: allow postNewMessage to target ticket by id or ref (#39360) POST /tickets/newmessage could only reach a ticket via its track_id (fetch was hardcoded to id=0). This resolves the ticket by id, then ref, then track_id (kept as fallback), so integrations that store the Dolibarr ticket id can append messages without knowing the track_id. --- htdocs/ticket/class/api_tickets.class.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/htdocs/ticket/class/api_tickets.class.php b/htdocs/ticket/class/api_tickets.class.php index d17269d9875..d620670198c 100644 --- a/htdocs/ticket/class/api_tickets.class.php +++ b/htdocs/ticket/class/api_tickets.class.php @@ -2,6 +2,7 @@ /* Copyright (C) 2016 Jean-François Ferry * Copyright (C) 2024-2025 Frédéric France * Copyright (C) 2024-2025 MDW + * Copyright (C) 2026 Jose Martinez * * 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 @@ -435,7 +436,14 @@ class Tickets extends DolibarrApi $this->ticket->$field = $this->_checkValForAPI($field, $value, $this->ticket); } $ticketMessageText = $this->ticket->message; - $result = $this->ticket->fetch(0, '', $this->ticket->track_id); + // Allow targeting the ticket by id or ref, not only track_id + if (!empty($this->ticket->id)) { + $result = $this->ticket->fetch($this->ticket->id); + } elseif (!empty($this->ticket->ref)) { + $result = $this->ticket->fetch(0, $this->ticket->ref); + } else { + $result = $this->ticket->fetch(0, '', $this->ticket->track_id); + } if (!$result) { throw new RestException(404, 'Ticket not found'); }