You are not logged in.
Pages: 1
Hey guys!
I'm starting in programming and i'm developing a Rest API using laravel and guzzle. However, when performing the post method to create a Ticket, postman gives that error:
GuzzleHttp\Exception\ClientException: Client error: `POST /apirest.php/ticket` resulted in a `400 Bad Request` response:
["ERROR_BAD_ARRAY","o parâmetro de entrada deve ser um vetor de objetos; ver documentação em seu navegador em https:/ (truncated...)
(This error description is PT-BR language)
This is my code
public function createTicket () {
$headers = [
'Content-type' => 'application/json',
'App-Token' => 'myapptoken',
'Session-Token' => 'mysessiontoken'
];
$data = array(
'entities_id' => 0,
'name' => "Infraestrutura | E-mail",
'content' => 'Perdi a senha do meu e-mail, teria como recuperar?',
'type' => 1,
'status' => 1,
'urgency' => 1,
'impact' => 1,
'priority' => 1,
'itilcategories_id' => 0
);
$client = new Client ([
'headers' => $headers,
'form_params' => $data
]);
$response = $client->request('POST','url/apirest.php/ticket',[
'headers' => [
$headers
],
'input' => [
$data,
]
]);
return $reponse-getBody()->getContents();
}
It my first experience in development REST Api, can someone help me?
OBS:
I removed the session-token and app token data for security reasons, but they are correct.
Offline
The input property should be set to $data not:
[
$data
]
I am not sure that the parameters you set when creating the client are needed either.
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
I solved using this
$params =
[ 'json' => [
'input' => [
'entities_id' => 0,
'name' => "Infraestrutura | E-mail",
'content' => 'teste passar requerente?',
'type' => 1,
'status' => 1,
'urgency' => 1,
'impact' => 1,
'priority' => 1,
'itilcategories_id' => 0,
'_users_id_requester' => 3878,
'groups_id' => 13
]
]
];
$client = new Client ([
'headers' => $headers
]);
$request = $client->request('POST','link/apirest.php/ticket' , $params);
$response = $request->getBody()->getContents();
return json_decode($response);
But I have one more question, how do I assign a ticket created to a group? I tried using 'groups_id' but without success.
Offline
to assign to a group add :
_groups_id_assign
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
Online
Solved using this
$params = [
// RequestOptions::JSON => [
// 'input' => [
// 'entities_id' => ,
// 'name' => '',
// 'content' => '',
// 'type' => 1,
// 'status' => 2,
// 'urgency' => 1,
// 'impact' => 1,
// 'priority' => 3,
// 'itilcategories_id' => 0,
// '_users_id_requester' => ,
// '_groups_id_assign' => ,
// '_users_id_assign' => ''
// ]
// ]
// ];
Thanks for help!
Offline
Pages: 1