You are not logged in.
Pages: 1
Hi All!
How I could update an actor or group?
I use this:
$ticket_id="81";
$userid="20";
$group_id="5";
$input='{ "input": {"tickets_id": '.$ticket_id.' ,"groups_id": '.$group_id.',"type": "2","use_notification": "1"}}';
$url=$api_url . "/Ticket/".$ticket_id."/group_ticket/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS,$input);
$request_result = curl_exec($ch);
curl_close ($ch);
$obj = json_decode($request_result,true);
print_r($request_result)
This ADD the Group_Id 5 to the ticket 81, but I want UPDATE, clear the assign group and put the 5.
I try changed PUT in POST, but It does'n work
Any ideas?
Thanks a lot!
Offline
I'm not sure but think you should update group_ticket and not ticket.
Trouver la panne avant de réparer...
GLPI10.0.16 (ubuntu 22.04 PHP8.1 Mariadb10.6 ) plugins : comportements 2.7.3 reports 1.16.0 formcreator 2.13.9, datainjection 2.13.5 fields 1.21.9
Offline
I try this with the same result
I try Delete first and then post, but it doesnt work
$group_id="5";
$hd_group_id="1";
$ticket_id=substr($text, 7,6);
if(is_numeric($ticket_id)) {
$input='{ "input": {"tickets_id": '.$ticket_id.' ,"groups_id": '.$hd_group_id.',"type": "2","use_notification": "1"}}';
$url=$api_url . "/group_ticket/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS,$input);
$request_result = curl_exec($ch);
curl_close ($ch);
$obj = json_decode($request_result,true);
print_r($request_result);
$input='{ "input": {"tickets_id": '.$ticket_id.' ,"groups_id": '.$group_id.',"type": "2","use_notification": "1"}}';
$url=$api_url . "/group_ticket/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS,$input);
$request_result = curl_exec($ch);
curl_close ($ch);
$obj = json_decode($request_result,true);
print_r($request_result);
Offline
$tickets_id="2223";
$url=$_SESSION['api_url']. "/Ticket/".$tickets_id."/group_ticket/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $_SESSION['headers']);
$json = curl_exec($ch);
curl_close ($ch);
$obj = json_decode($json,true);
print_r($obj);
// you get an array withe all grroups (assigned, observer, requester) linked to the ticket;
// then pick un the ID you need (loop into array => initiate$group_ticket_id ;
$group_ticket_id ="MyID";
$group_id="MyGroupID";
$url=$_SESSION['api_url']. "/group_ticket/".$group_ticket_id."/";
$input='{ "input": {"id" : "'.$group_ticket_id.'","groups_id": "'.$group_id.'","type": "2","use_notification": "1"}}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS,$input);
$request_result = curl_exec($ch);
curl_close ($ch);
$obj = json_decode($request_result,true);
print_r($request_result);
Trouver la panne avant de réparer...
GLPI10.0.16 (ubuntu 22.04 PHP8.1 Mariadb10.6 ) plugins : comportements 2.7.3 reports 1.16.0 formcreator 2.13.9, datainjection 2.13.5 fields 1.21.9
Offline
Perfect! This was the solution
$url=$api_url . "/Ticket/".$ticket_id."/group_ticket/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$json = curl_exec($ch);
curl_close ($ch);
$obj = json_decode($json,true);
$gp_ticket_id= $obj[0][id]; //Get the ID value
//And Update it //
$url=$api_url . "/group_ticket/".$gp_ticket_id."/";
$input='{ "input": {"id" : "'.$gp_ticket_id.'","groups_id": "'.$group_id.'","type": "2","use_notification": "1"}}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS,$input);
$request_result = curl_exec($ch);
curl_close ($ch);
$obj = json_decode($request_result,true);
print_r($request_result);
If ticket has 2 groups assigned, this only change the first. In our case, the tickets only has 1 group assigned. In other case, maybe we need loop the array and count the number of groups assigned and only change wich we want.
Thanks a lot!
Offline
may be check if "type=2" in the group you want to be replaced.
Trouver la panne avant de réparer...
GLPI10.0.16 (ubuntu 22.04 PHP8.1 Mariadb10.6 ) plugins : comportements 2.7.3 reports 1.16.0 formcreator 2.13.9, datainjection 2.13.5 fields 1.21.9
Offline
Pages: 1