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 2019-10-09 21:59:06

ronnie.peeters
Member
From: Eindhoven, the Netherlands
Registered: 2016-10-09
Posts: 72

[SOLVED]create ticket and add computer to it

Hello all,

I am struggling with ticket creating using the rest api.

I am able to create a new ticket and set my needed settings.
Additionally I want to associate a computer with this new ticket.
Even add a technician group.

But I am nuable to figure out how to do this.
Does anybody have an example json for me?


GLPI 9.4.3 - Currently in Dev environment - preparing for production
-Preparing data migration from OSTicket to GLPI for the Ticketing/Helpdesk part.
-Preparing data migration from OrangeSCRUM to GLPI for the project management part.
@Working at a company that is responsible for the IT environment of over 4500 employees that have IT assets

Offline

#2 2019-10-09 22:45:42

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

Re: [SOLVED]create ticket and add computer to it

to add assigned users and assigned groups to tickets i make it so

 add assigned user ( technician) to ticket

    $ticket_id="MyTicketID";
    $user_id="IdOfTheTechnician";
    $input='{ "input": {"tickets_id": '.$ticket_id.' ,"users_id": '.$user_id.',"type": "2","use_notification": "1"}}';
    $url=$api_url . "/Ticket/".$ticket_id."/Ticket_User/";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
    curl_setopt($ch, CURLOPT_POSTFIELDS,$input);
    $json = curl_exec($ch);
    curl_close ($ch);

    for debug you can add :
    $obj = json_decode($json,true);
    echo "<br/>".$input."<br/>";
    print_r($json);

Add groups to ticket

    $group_id="MyGroupIDto Assign";
    $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_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
    curl_setopt($ch, CURLOPT_POSTFIELDS,$input);

    $json = curl_exec($ch);
    curl_close ($ch);
    $obj = json_decode($json,true);
    echo "<br/>".$input."<br/>";
    print_r($json);

note : in $input='{ "input": {"tickets_id": '.$ticket_id.' ,"groups_id": '.$group_id.',"type": "2","use_notification": "1"}}';
you can change type to
1) requester
2)assigned
3)observer


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

Offline

#3 2019-10-09 23:10:45

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

Re: [SOLVED]create ticket and add computer to it

to associate computer to ticket

$ticketid=MyTicketID;
$computerid='MyComputerID';
$url="/Ticket/".$ticketid."/Item_ticket/";
$fields = '{"input": { "items_id":'.$computerid.',"itemtype":"Computer","tickets_id":'.$ticketid.'}}'  ;
$ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
    curl_setopt($ch, CURLOPT_POSTFIELDS,$fields);

    $json = curl_exec($ch);
    curl_close ($ch);

//only for debug add:;
    $obj = json_decode($json,true);
    echo "<br/>".$fields."<br/>";
    print_r($json);

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

Offline

#4 2020-07-13 16:50:48

ronnie.peeters
Member
From: Eindhoven, the Netherlands
Registered: 2016-10-09
Posts: 72

Re: [SOLVED]create ticket and add computer to it

LaDenrée: Thank you! These replies were very helpfull!


GLPI 9.4.3 - Currently in Dev environment - preparing for production
-Preparing data migration from OSTicket to GLPI for the Ticketing/Helpdesk part.
-Preparing data migration from OrangeSCRUM to GLPI for the project management part.
@Working at a company that is responsible for the IT environment of over 4500 employees that have IT assets

Offline

Board footer

Powered by FluxBB