Solved

Facing issues accessing curl api

  • 17 December 2022
  • 5 replies
  • 864 views

Badge +3

Hi Team,

I am not able to access 

curl -X 'GET' \  'https://<webserver>/webconsole/api/v4/Servers?showOnlyInfrastructureMachines=1' \  -H 'accept: application/json'

Getting “Access Denied” while using it.

When try to access the same using browser , it asks to login and then it works. However, when we pass username and password in curl. I get “401- Unauthorized”.

Can you help with the correct syntax using curl?

icon

Best answer by chrisknows 19 December 2022, 15:01

View original

5 replies

Userlevel 3
Badge +10

Your header needs to include an authcode

Userlevel 7
Badge +23

Your header needs to include an authcode

👆👌

https://api.commvault.com has much more verbose documentation and contains the CURL syntax in the examples. For authentication: https://api.commvault.com/#96595921-4cc1-4f2b-ab87-c3ec20c02f68

curl --location --request POST 'http://WebConsoleHostName/webconsole/api/Login' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data-raw '{
"password": "<Base64 Encoded Password>",
"username": "<UserName>"
}'

 

Once you have the authentication token you can include it in the header like @chrisknows mentioned - in this example to get all clients

curl --location --request GET 'http://WebConsoleHostName/webconsole/api/Client?hiddenclients=true' \ --header 'Accept: application/json' \ --header 'Authtoken: QSDK token would be auto set after POST Login is called.' 

 

Badge +3

Thanks @Damian Andre for the clarification.

So, if I understand correctly then are 

http://WebConsoleHostName/webconsole/api/Client?hiddenclients=true

and 

https://<webserver>/webconsole/api/v4/Servers?showOnlyInfrastructureMachines=1' same?

If not then I need to use the latter one. Can you confirm if the way of invocation is same for both of them?

Userlevel 3
Badge +10

No, that’s not what he is saying, the latter code sample was just an example that highlights that 

All api requests have to include an auth code in the header.

That is why you are getting a 401 error, because you are not telling the webserver who you are.

So the first step in any api request is that you first authenticate/login to get an authcode.

Once you have an authcode, you can then submit whatever api request you want.

Please read this carefully to get more details on the authentication process.

Badge +3

Got that, thanks @chrisknows 

Will try that out

Reply