Skip to main content

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

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


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'

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

 


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


Hi,

 

I have a similar problem:

 

 curl --silent --location 'http://centreon/api/index.php?action=action&object=centreon_clapi' -H 'Content-Type: application/json' -H 'centreon-auth-token:'someToken' -d {  "action": "show", "object": "HOST" }

 

return

<!doctype html><html lang="en"><head><meta charset="utf-8"><link rel="shortcut icon" href="./img/favicon.ico"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name="theme-color" content="#000000"><base href="/centreon/"><title>Centreon - IT & Network Monitoring</title><script defer="defer" src="./static/runtime~main.075495a8.js"></script><script defer="defer" src="./static/main.1d072c65.js"></script></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root" style="height:100%"></div></body></html>

 

What s wrong??

Thanks

 


idem with

curl -d '{  "action": "show", "object": "HOST" }' -H 'Content-Type: application/json' -H 'centreon-auth-token:'someToken' -X POST 'http://centreon/api/index.php?action=action&object=centreon_clapi'

 

 

 


Hello,

I don’t know if it’s your URL example is similar to the one you use for your API request,

But i think you need to add /centreon/ between your Centreon’s IP/DN and /api

#URL you used (in your example)
http://centreon/api/index.php?action=action&object=centreon_clapi

#URL you should try
http://centreon/centreon/api/index.php?action=action&object=centreon_clapi

Hope it helps


That s work!

Excellent !

You save my day!

😀

 


Reply