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 2023-05-23 15:35:33

Peppaul
Member
Registered: 2023-05-23
Posts: 2

GLPI API Add a ticket

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

#2 2023-05-23 15:44:57

Peppaul
Member
Registered: 2023-05-23
Posts: 2

Re: GLPI API Add a ticket

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

Board footer

Powered by FluxBB