You are not logged in.
Hello,
I'm encountering an issue while trying to create an ITILCategory using the GLPI API. I receive the following error message:
["ERROR_BAD_ARRAY","The input parameter must be an array of objects; see the documentation in your browser at http://your-glpi-url/apirest.php/#ERROR_BAD_ARRAY"]
I've tried sending the request with different formats, but none seem to resolve the issue. Here's a portion of my PHP script:
<?php
$api_url = 'http://url/apirest.php/';
$user_token = 'user_token';
$app_token = 'app_token';function get_session_token($api_url, $user_token, $app_token) {
$url = $api_url . 'initSession';
// cURL setup and execution here
}function api_post($url, $data, $user_token, $app_token, $session_token) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($data),
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
"App-Token: $app_token",
"Session-Token: $session_token",
"Authorization: user_token $user_token"
),
));
$response = curl_exec($curl);
// Handle response and errors here
}$post_data = [
'entities_id' => 13,
'is_recursive' => 1,
// Other fields here
];$url = $api_url . "Entity/13/ITILCategory/";
$response = api_post($url, $post_data, $user_token, $app_token, $session_token);if ($response && isset($response['id'])) {
echo "Category created: ID " . $response['id'];
} else {
echo "Failed to create category. Response: ";
print_r($response);
}?>
Additional Information:
The endpoint used is Entity/13/ITILCategory/.
I've ensured that all required fields are included and correctly formatted.
Any help or insights on resolving this issue would be greatly appreciated.
Thank you!
Offline
The fields are not formatted correctly. The current API requires all of the data to be in an "input" property like so:
{
"input": {
// Your fields here
}
}
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