You are not logged in.
Pages: 1
Hello,
I am using a php script to create a ticket in GLPI. Here's my script:
<?php
$apiURL = "https://XXXX/apirest.php/Ticket";
$headers = [
"App-token: XXXX",
"Session-token: XXXX"
];
$data = [
"input" => [
"name" => "test"
]
];
$dataencoded=json_encode($data);
echo $dataencoded;
$ch = curl_init($apiURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataencoded);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
$error = curl_error($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($result) {
echo $result;
} else {
echo "Error creating ticket: " . $error;
echo "HTTP Code: " . $httpCode;
}
?>
When I execute it, I got this result:
{"input":{"name":"test"}}["ERROR_BAD_ARRAY"The input parameter must be an array of objects; View documentation in your browser at"https://XXXX/apirest.php/#ERROR_BAD_ARRAY"]
As we can see, $dataencoded is also a good JSON array. I also tried the exact same thing on POSTMAN wiht the exact same json array and it works.
My question is: Why is it a bad array?
Thank you for your future help.
Offline
Quick reply because quick fix:
The issue was in the header, you just need to add in the header array:"Content-Type: application/json"
Offline
Pages: 1