Skip to main content
Solved

Api request returning unauthorized

  • June 8, 2022
  • 1 reply
  • 779 views

Forum|alt.badge.img+2

Hello everyone,

I am trying to get metric results using rest api request.

I have enabled the rights to reach api configuration for the user.

I get the api token by giving credentials via action authenticate

But when i use the token i get unauthorized access.

Here are the commands used :

 

 

curl -v -d "username=admin&password=centreon" -H "Content-Type: application/x-www-form-urlencoded" -X POST http://172.20.10.2/centreon/api/index.php?action=authenticate

 

 

curl -v http://172.20.10.2/centreon/api/index.php?object=centreon_realtime_services^&action=list -H 'Content-Type:application/json' -H 'X-AUTH-TOKEN:6hwVYFtJerPts6JHopkN1qlZQ0xPo32DIUg2hOyyy220PPvQ3ANBWqiyEl11pxpv'

 

And some screens for the result : 

 

 

Best answer by trhdsh

syntax error : the problem was using single quotes in the command

changed the command to de following worked :

 

curl -v http://172.20.10.2/centreon/api/index.php?object=centreon_realtime_services^&action=list -H “Content-Type:application/json” -H “X-AUTH-TOKEN:”6hwVYFtJerPts6JHopkN1qlZQ0xPo32DIUg2hOyyy220PPvQ3ANBWqiyEl11pxpv””

1 reply

Forum|alt.badge.img+2
  • Author
  • Steward *
  • Answer
  • June 8, 2022

syntax error : the problem was using single quotes in the command

changed the command to de following worked :

 

curl -v http://172.20.10.2/centreon/api/index.php?object=centreon_realtime_services^&action=list -H “Content-Type:application/json” -H “X-AUTH-TOKEN:”6hwVYFtJerPts6JHopkN1qlZQ0xPo32DIUg2hOyyy220PPvQ3ANBWqiyEl11pxpv””