You are not logged in.
Pages: 1
Hi All!
I want modify the status of tickets using API, but I cant
This is the code
//Iniciar Sesion//
$api_url="myurl";
$user_token="myusertoken";
$app_token="myapptoken";
$ch = curl_init();
$url=$api_url . "/initSession?Content-Type=%20application/json&app_token=".$app_token ."&user_token=".$user_token;
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$json = curl_exec($ch);
curl_close ($ch);
$obj = json_decode($json,true);
$sess_token = $obj['session_token'];
$headers =array(
'Content-Type: application/json',
'App-Token: ' .$app_token,
'Session-Token: '.$sess_token
);
// Modificar //
$ticket_id="ticketID";
$status="5";
$input='{ "input": {"tickets_id": '.$ticket_id.' ,"status": '.$status.' ,"solvedate": '.date("Y-m-d H:i:s").'}}';
$url=$api_url . "/Ticket/".$ticket_id."/";
$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);
Whats wrong?
Thank you very much
Offline
did you try to replace
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
with
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
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
did you try to replace
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
with
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
I try now, but nothing happens
Where I can see any log or debug for this operation?
$ticket_id="80";
$status="5";
$input='{ "input": {"tickets_id": '.$ticket_id.' ,"status": '.$status.' ,"solvedate": '.date("Y-m-d H:i:s").'}}';
$url=$api_url . "/Ticket/".$ticket_id."/";
This is right?
Offline
you can add
print_r($input);
print_r($json);
to get server answer
not sure about quote and doublequote but i would have written so :
$input='{ "input": {"tickets_id": "'.$ticket_id.'" ,"status": "'.$status.'" ,"solvedate": "'.date("Y-m-d H:i:s").'" }}';
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
Still not working
$url: http://glpi2018.<mydomain>/apirest.php/Ticket/80/
$input: { "input": {"tickets_id": "80" ,"status": "5" ,"solvedate": "2017-11-24 12:10:25"}}
$json: ERR 404
<!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>
<title>IIS 8.0 Detailed Error - 404.0 - Not Found</title>
<style type="text/css">
<!--
body{margin:0;font-size:.7em;font-family:Verdana,Arial,Helvetica,sans-serif;}
code{margin:0;color:#006600;font-size:1.1em;font-weight:bold;}
.config_source code{font-size:.8em;color:#000000;}
pre{margin:0;font-size:1.4em;word-wrap:break-word;}
ul,ol{margin:10px 0 10px 5px;}
ul.first,ol.first{margin-top:5px;}
fieldset{padding:0 15px 10px 15px;word-break:break-all;}
.summary-container fieldset{padding-bottom:5px;margin-top:4px;}
legend.no-expand-all{padding:2px 15px 4px 10px;margin:0 0 0 -12px;}
legend{color:#333333;;margin:4px 0 8px -12px;_margin-top:0px;
font-weight:bold;font-size:1em;}
a:link,a:visited{color:#007EFF;font-weight:bold;}
a:hover{text-decoration:none;}
h1{font-size:2.4em;margin:0;color:#FFF;}
h2{font-size:1.7em;margin:0;color:#CC0000;}
h3{font-size:1.4em;margin:10px 0 0 0;color:#CC0000;}
h4{font-size:1.2em;margin:10px 0 5px 0;
}#header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS",Verdana,sans-serif; color:#FFF;background-color:#5C87B2;
}#content{margin:0 0 0 2%;position:relative;}
.summary-container,.content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;}
.content-container p{margin:0 0 10px 0;
}#details-left{width:35%;float:left;margin-right:2%;
}#details-right{width:63%;float:left;overflow:hidden;
}#server_version{width:96%;_height:1px;min-height:1px;margin:0 0 5px 0;padding:11px 2% 8px 2%;color:#FFFFFF; background-color:#5A7FA5;border-bottom:1px solid #C1CFDD;border-top:1px solid #4A6C8E;font-weight:normal; font-size:1em;color:#FFF;text-align:right;
}#server_version p{margin:5px 0;}
table{margin:4px 0 4px 0;width:100%;border:none;}
td,th{vertical-align:top;padding:3px 0;text-align:left;font-weight:normal;border:none;}
th{width:30%;text-align:right;padding-right:2%;font-weight:bold;}
thead th{background-color:#ebebeb;width:25%;
}#details-right th{width:20%;}
table tr.alt td,table tr.alt th{}
.highlight-code{color:#CC0000;font-weight:bold;font-style:italic;}
.clear{clear:both;}
.preferred{padding:0 5px 2px 5px;font-weight:normal;background:#006633;color:#FFF;font-size:.8em;}
-->
</style>
</head>
<body>
<div id="content">
<div class="content-container">
<h3>HTTP Error 404.0 - Not Found</h3>
<h4>The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.</h4>
</div>
<div class="content-container">
<fieldset><h4>Most likely causes:</h4>
<ul> <li>The directory or file specified does not exist on the Web server.</li> <li>The URL contains a typographical error.</li>
<li>A custom filter or module, such as URLScan, restricts access to the file.</li> </ul>
</fieldset>
</div>
<div class="content-container">
<fieldset><h4>Things you can try:</h4>
<ul> <li>Create the content on the Web server.</li> <li>Review the browser URL.</li> <li>Create a tracing rule to track failed requests for this HTTP status code and see which module is calling SetStatus. For more information about creating a tracing rule for failed requests, click <a href="http://go.microsoft.com/fwlink/?LinkID=66439">here</a>. </li> </ul>
</fieldset>
</div>
<div class="content-container">
<fieldset><h4>Detailed Error Information:</h4>
<div id="details-left">
<table border="0" cellpadding="0" cellspacing="0">
<tr class="alt"><th>Module</th><td> IIS Web Core</td></tr>
<tr><th>Notification</th><td> MapRequestHandler</td></tr>
<tr class="alt"><th>Handler</th><td> StaticFile</td></tr>
<tr><th>Error Code</th><td> 0x80070002</td></tr>
</table>
</div>
<div id="details-right">
<table border="0" cellpadding="0" cellspacing="0">
<tr class="alt"><th>Requested URL</th><td> http://<myserver>:80/apirest.php/Ticket/80/</td></tr>
<tr><th>Physical Path</th><td> <glpipath>\apirest.php\Ticket\80\</td></tr>
<tr class="alt"><th>Logon Method</th><td> Anonymous</td></tr>
<tr><th>Logon User</th><td> Anonymous</td></tr>
</table>
<div class="clear"></div>
</div>
</fieldset>
</div>
<div class="content-container">
<fieldset><h4>More Information:</h4>
This error means that the file or directory does not exist on the server. Create the file or directory and try the request again.
<p><a href="http://go.microsoft.com/fwlink/?LinkID=62293&IIS70Error=404,0,0x80070002,9200">View more information »</a></p>
</fieldset>
</div>
</div>
</body>
</html>
Last edited by Drumhazzard (2017-12-13 14:10:39)
Offline
let's debug from beginning :
check if api ini works :
//Iniciar Sesion//
$api_url="myurl";
$user_token="myusertoken";
$app_token="myapptoken";
$ch = curl_init();
$url=$api_url . "/initSession?Content-Type=%20application/json&app_token=".$app_token ."&user_token=".$user_token;
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$json = curl_exec($ch);
curl_close ($ch);
$obj = json_decode($json,true);
$sess_token = $obj['session_token'];
$headers =array(
'Content-Type: application/json',
'App-Token: ' .$app_token,
'Session-Token: '.$sess_token
);
echo "<br/> init session :";
print_r($obj);
echo "<br/> session ".$sess_token;
echo "<br/> headers";
print_r($headers);
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
Seems Ok.
>php test_api.php
<br/> init session :Array
(
[session_token] => t32ifoaj5fgpqvhkk4398h50n2
)
<br/> session t32ifoaj5fgpqvhkk4398h50n2<br/> headersArray
(
[0] => Content-Type: application/json
[1] => App-Token: VTeincnHlycEFZYmbGxTCtBgH9i3637uHmoPwLbQ
[2] => Session-Token: t32ifoaj5fgpqvhkk4398h50n2
)
Offline
sorry,
error 404 :
is your api client on the same server than GLPI ?
then try url ="http://localhost/var/www/html/glpi/apirest.php";
edit : didn't see your previous answer.
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
sorry,
error 404 :
is your api client on the same server than GLPI ?
then try url ="http://localhost/var/www/html/glpi/apirest.php";
Ups! Windows Server xD GLPI runs in IIS
We check with D:\<myglpiroute>\apirest.php, but nothing happens.
I put in "$api_url" the DNS name not localhost
For example:
$api_url="http://glpi2018.mydomain.com/apirest.php";
Last edited by Drumhazzard (2017-11-24 15:33:14)
Offline
Hi All!
Somebody have an idea that how I can fix it?
Last edited by Drumhazzard (2017-11-27 09:28:35)
Offline
Bump!
Offline
you can get session token, it means your api works.
in glpi GUI, can you solve a ticket without solution, without category and so on ????
can you change ticket #80 status ?, Can you set solve date ?
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
In GLPI GUI all works fine.
Where I can see all the parameters that I can pass through API REST?
Maybe with only solved date and tickets status it's not enought
Could you check if my sentence works in your system?
Thanks a lot
Offline
this works :
$ticket_id="2223";
$status="5";
$url=$_SESSION['api_url'] . "/Ticket/".$ticket_id."/";
$fields='{ "input": {"tickets_id": "'.$ticket_id.'" ,"status" : "'.$status.'" ,"solvedate": "'.date("Y-m-d H:i:s").'"}}';
$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, $_SESSION['headers']);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$request_result = curl_exec($ch);
curl_close ($ch);
$obj = json_decode($request_result,true);
print_r($obj);
JSON was invalid : double quote missing for date
$fields='{ "input": {"tickets_id": "'.$ticket_id.'" ,"status" : "'.$status.'" }}'; gives same results : if you set to solved, glpi records current datetime as solve date
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
It's enought for me. I will check my ISS rules.
Thank you very much.
With this I have a Telegram Bot thats can resolve tickets
Offline
you could also add a solution : "Ticket automatically solved by Telegram Bot"
i move this post into API section
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
Excelent Idea!
Offline
Hi @Drumhazzard,
From what I understand you created the function of solving the ticket via telegram.. That's it?
I've been behind this solution for some time now, is it a plugin? Could you share?
Offline
Pages: 1