Solved

REST API v1 host categories don't work

  • 20 November 2023
  • 4 replies
  • 161 views

Userlevel 1
Badge +7

Hi, I’m trying to add a host into “host categories” in my centreon server using Rest API v1, but it seems to not work properly:
The command

curl --silent --location 'http://centreon.local/centreon/api/index.php?action=authenticate' --header 'centreon-auth-token: some_secret' --header 'Content-Type: application/json' --data '{
"object": "HC",
"action": "addmember",
"values": "mycategorie;my.host.lan"
}'

The result:
400Bad Request → "Bad parameters"

But going to the server and executing the command, it works.

centreon -u admin -p 'some_secret' -o HC -a addmember -v "mycategorie;my.host.lan"

centreon -u admin -p 'some_secret' -o HC -a getmember -v "mycategorie"
id;name
2787;my.host.lan


I’m missing something?
https://docs.centreon.com/docs/api/rest-api-v1/#host-categories
https://docs.centreon.com/docs/api/clapi/#addmember-and-setmember

icon

Best answer by ruben_mendez 23 November 2023, 15:15

View original

4 replies

Userlevel 5
Badge +11

Hello,

To make requests to Centreon API v1, you need 2 requests

The first one to authenticate, this request will give you a token to use for the second request

The token expire 2 hours after its creation

https://docs.centreon.com/docs/api/rest-api-v1/#authentication

And then you put the token on the header ‘centreon-auth-token’ with your arguments

https://docs.centreon.com/docs/api/rest-api-v1/#getting-started

 

In the curl request you write on your message, your request is good but the endpoint you use is the authentication endpoint

The correct endpoint to manipulate Centreon objects (like categories) is

http://centreon.local/centreon/api/index.php?action=action&object=centreon_clapi

 

Regards

Userlevel 1
Badge +7

Yeah, I know that, some_secret is the token. I often work with centreon API v1. However, host categories don't work.

--header 'centreon-auth-token: some_secret'
Userlevel 5
Badge +11

Hello,

What version of Centreon are you using?

Can you re-check the endpoint you are using during the second request? The one in your the example is wrong ( “index.php?action=authenticate” instead of “index.php?action=action&object=centreon_clapi”) but it’s maybe a copy-paste mistake

I tested on 23.10 and everything seems to be working for this request

 

Userlevel 1
Badge +7

My bad is “?action=action&object=centreon_clapi” not “?action=authenticate”.
Thank you 👌

Reply