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-03 13:48:43

Danny MDJ
Member
Registered: 2019-10-03
Posts: 2

Add Items - Input Ticket give Error_Bad_Array

Hi everyone,

I need to assigned technician to ticket, i use for that the python requests module.
When i use :

requests.put(url = url, headers = headers, data = input, verify=False)
It give me an 200 OK answer, but is not working.

What is strange is the fact that I test to do the request with php - curl on 2 environments (Glpi on Debian and Test GLPI on centOS 7).

With this code:

<?php
$api_url="";
$user_token="";
$app_token="";
$ch = curl_init();
$url=$api_url . "initSession?Content-Type=%20application/json&app_token=".$app_token ."&user_token=".$user_token;
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
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 
    );

$ticket_id=X;
$user_id=Y;
$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, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
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);

$json2 = curl_exec($ch);
curl_close ($ch);
...
?>

It work fine on test environment, but on the other it will return "ERROR_BAD_ARRAY The input parameter must be an array of objects"

Any idea ?

Thanks a lot smile

Offline

#2 2020-07-28 17:21:07

Pynch
Member
Registered: 2018-11-22
Posts: 2

Re: Add Items - Input Ticket give Error_Bad_Array

This is very old, but I came across it and thought I would answer so future people know.

$input='{ "input": {"tickets_id": '.$ticket_id.' ,"users_id": '.$user_id.',"type": "2","use_notification": "1"}}';

The error is quite clear, your input must be an array:

$input='{ "input": [{"tickets_id": '.$ticket_id.' ,"users_id": '.$user_id.',"type": "2","use_notification": "1"}]}';

That should work smile

Offline

Board footer

Powered by FluxBB