You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2017-12-05 10:03:24

Drumhazzard
Member
Registered: 2011-09-19
Posts: 47

Update (Not Add) Users or Groups

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

#2 2017-12-05 12:16:52

LaDenrée
HELPER
Registered: 2012-11-19
Posts: 6,145

Re: Update (Not Add) Users or Groups

I'm not sure but  think  you should update group_ticket and not ticket.


Trouver la panne avant de réparer...
GLPI10.0.10 (ubuntu 22.04 PHP8.1  Mariadb10.6 ) plugins : comportements 2.7.2 reports 1.16.0 formcreator 2.13.8, datainjection 2.13.4 fields 1.21.6

Online

#3 2017-12-05 15:59:46

Drumhazzard
Member
Registered: 2011-09-19
Posts: 47

Re: Update (Not Add) Users or Groups

I try this with the same result sad

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

#4 2017-12-06 01:28:21

LaDenrée
HELPER
Registered: 2012-11-19
Posts: 6,145

Re: Update (Not Add) Users or Groups

$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.10 (ubuntu 22.04 PHP8.1  Mariadb10.6 ) plugins : comportements 2.7.2 reports 1.16.0 formcreator 2.13.8, datainjection 2.13.4 fields 1.21.6

Online

#5 2017-12-07 10:58:36

Drumhazzard
Member
Registered: 2011-09-19
Posts: 47

Re: Update (Not Add) Users or Groups

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

#6 2017-12-07 11:42:14

LaDenrée
HELPER
Registered: 2012-11-19
Posts: 6,145

Re: Update (Not Add) Users or Groups

may be check if "type=2" in the group you want to be replaced.


Trouver la panne avant de réparer...
GLPI10.0.10 (ubuntu 22.04 PHP8.1  Mariadb10.6 ) plugins : comportements 2.7.2 reports 1.16.0 formcreator 2.13.8, datainjection 2.13.4 fields 1.21.6

Online

Board footer

Powered by FluxBB