Solved

API request "Unauthorized"

  • 25 November 2022
  • 4 replies
  • 876 views

Badge +1

Hi everyone,

I saw a topic that exposes a similar problem but unfortunately the answer is not sufficient.

I manage to generate a token but every request i do, the result is the same.
I put you in the context, I manage a Centreon with 300 hosts but without license. Is there a connection with this problem?

 

C:\Users\dorian>curl -v https://SERVER/centreon/api/index.php?object=centreon_realtime_services^&action=list -H "Content-Type:application/json" -H "X-AUTH-TOKEN:"TOKEN""
*   Trying 192.168.90.63:443...
* Connected to SERVER (192.168.90.63) port 443 (#0)
* schannel: disabled automatic use of client certificate
* ALPN: offers http/1.1
* ALPN: server accepted http/1.1
> GET /centreon/api/index.php?object=centreon_realtime_services&action=list HTTP/1.1
> Host: SERVER
> User-Agent: curl/7.83.1
> Accept: */*
> Content-Type:application/json
> X-AUTH-TOKEN:kkMNbGrJYJw6xm8RuQIfgCl8GyL7OfsbI2TvLT+hKIkez+4ZrDW+sLazqY3LXviJ
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 401 Unauthorized
< Date: Fri, 25 Nov 2022 09:05:10 GMT
< Server: Apache
< X-Powered-By: PHP/8.0.20
< X-Frame-Options: sameorigin
< Transfer-Encoding: chunked
< Content-Type: application/json;charset=utf-8
<
"Unauthorized"* Connection #0 to host SERVER left intact

icon

Best answer by Jérémy Jaouen 25 November 2022, 16:08

View original

4 replies

Userlevel 3
Badge +4

Hello, X-AUTH-TOKEN is the header use for the api v2 , 

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

This documentation should be more helpful.

Generate a token with the authenticate endpoint then use header “centreon-auth-token”.

Badge +1

I have read this documentation so much times, every request I do, “Unauthorized” appears.

At first, the documentation indicates simple quotes, is this the correct syntax?

Otherwise, when calling multiple actions, should I put "&" or "^&" between them?

I had found a tutorial that explains how to use the REST API v1 with sample requests :

https://www.sugarbug.fr/atelier/techniques/ihmweb/centreon/api-rest/

Do you have any comments on the tutorial or do you have an example command to give me to test the connectivity of my API?

 

Userlevel 3
Badge +4

centreon-auth-token should be used as a header (instead of X-AUTH-TOKEN) and not as an url parameter

```
curl -v https://SERVER/centreon/api/index.php?object=centreon_realtime_services^&action=list -H "Content-Type:application/json" -H "centreon-auth-token:TOKEN"

```

Badge +1

Thanks a lot !

Reply