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 2018-10-19 12:14:57

aerozol
Member
Registered: 2018-10-19
Posts: 4

RESTful API usage for ticket update

Hi guys,
I have a problem with structure of object when i want to change it.

  $obj = [
        "input" => [
            "_date" => "04-10-2018 09:44",
            "date" => "2018-10-04 09:44:13",
            "users_id_recipient" => "487",
//            "_time_to_own" => " ",
//            "time_to_own" => " ",
//            "_time_to_resolve" => " ",
//            "time_to_resolve" => " ",
//            "_internal_time_to_own" => " ",
//            "internal_time_to_own" => " ",
//            "_internal_time_to_resolve" => " ",
//            "internal_time_to_resolve" => " ",
            "type" => "1",
            "itilcategories_id" => "0",
            "status" => "1",
            "requesttypes_id" => "1",
            "urgency" => "3",
            "global_validation" => "1",
            "impact" => "3",
            "locations_id" => "5",
            "priority" => "3",
            "my_items" => "",
            "itemtype" => "0",
            "items_id" => "0",
            "_itil_requester" => ["_type" => " 0"],
            "_itil_observer" => [
                "_type" => "user",
                "users_id" => "487",
                "use_notification" => [1],
                "alternative_email" => ["some_mail@gmai.com]
            ],
            "_itil_assign" => ["_type" => " 0"],
            "name" => "NEW TICKET",
            "content" => "<p>NEW TICKET BY REST</p>",
            "_link" =>
                ["link" => " 1",
                    "tickets_id_1" => "110",
                    "tickets_id_2" => "0"
                ],
            "filename" => [" (binary)"],
            "update" => "Save",
            "_read_date_mod" => "2018-10-18 14:43:40",
            "id" => "112"
        ],
        "format" => 'json'
    ];

When i'm trying to update the ticket and assign watchers (_itil_observer) or assigned users (_itil_assign) the request din't change anything. It's work correct in interface but i cant implement it in request.
Can you tell me where is my mistake? Thanks!

Offline

#2 2018-10-22 14:04:02

aerozol
Member
Registered: 2018-10-19
Posts: 4

Re: RESTful API usage for ticket update

I'ts not possible to set observers and assigned users from api  at the moment .
In the api.class.php

 //update item
                        $object = Toolbox::sanitize((array)$object);

returns only one level key=>value object. When you set in dept like

"_itil_observer" => [
                "_type" => "user",
                "users_id" => "487",
                "use_notification" => [1],
                "alternative_email" => ["some_mail@gmai.com]
            ]

the function returns empty string...

Last edited by aerozol (2018-10-22 14:04:48)

Offline

#3 2018-10-22 16:36:03

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

Re: RESTful API usage for ticket update

if you want to add users to a ticket :

$url=$api_url . "/Ticket/".$ticket_id."/Ticket_User/";
method POST
$input='{ "input": {"tickets_id": '.$ticket_id.' ,"users_id": '.$user_id.',"type": "2","use_notification": "1"}}';

with type :
   // Requester  1;
   // Assign    2;
   // Observer  3;


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

#4 2018-10-30 16:02:28

aerozol
Member
Registered: 2018-10-19
Posts: 4

Re: RESTful API usage for ticket update

Thanks solved

Offline

#5 2019-06-18 17:43:55

ykatir22
Member
Registered: 2019-05-17
Posts: 9

Re: RESTful API usage for ticket update

Hi,
I try to change my GLPI ticket status to closed but i have a servor error, Can anyone help me to solve it

the call URL was : apirest.php/Tikcet/$tickets_id
body :{"input":{"tickets_id":"1906180012","status":"6"}}

the response was :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>500 - Internal server error.</title>
<style type="text/css">
<!--
body{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;}
fieldset{padding:0 15px 10px 15px;}
h1{font-size:2.4em;margin:0;color:#FFF;}
h2{font-size:1.7em;margin:0;color:#CC0000;}
h3{font-size:1.2em;margin:10px 0 0 0;color:#000000;}
#header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS", Verdana, sans-serif;color:#FFF;
background-color:#555555;}
#content{margin:0 0 0 2%;position:relative;}
.content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;}
-->
</style>
</head>
<body>
<div id="header"><h1>Server Error</h1></div>
<div id="content">
<div class="content-container"><fieldset>
  <h2>500 - Internal server error.</h2>
  <h3>There is a problem with the resource you are looking for, and it cannot be displayed.</h3>
</fieldset></div>
</div>
</body>
</html>

Offline

#6 2019-06-18 19:49:46

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

Re: RESTful API usage for ticket update

Mistype  in url tikcet should be 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

#7 2022-02-21 12:54:45

shuriban
Member
Registered: 2021-09-07
Posts: 3

Re: RESTful API usage for ticket update

It worked for me
For change group "_groups_id_assign"

 public function changeGroup($taskId, $group)
    {
        $method = 'POST';
        $data = [
            "input" => [
                'tickets_id' => $taskId,
                'groups_id' => $group,
                'type' => 2,
                'use_notification' => 1
            ]
        ];
        return $this->request($method, 'Ticket/'.$taskId.'/Group_Ticket', json_encode($data));
    }

Offline

#8 2022-02-21 13:36:23

cconard96
Moderator
Registered: 2018-07-31
Posts: 2,809
Website

Re: RESTful API usage for ticket update

This was fixed in:
https://github.com/glpi-project/glpi/pull/9171

It was included in version 9.5.6.


GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.

Offline

Board footer

Powered by FluxBB