Skip to main content
Answer

Facing issues accessing curl api

  • December 17, 2022
  • 5 replies
  • 1269 views

Forum|alt.badge.img+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?

Best answer by chrisknows

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.

5 replies

chrisknows
Byte
Forum|alt.badge.img+10
  • Byte
  • December 17, 2022

Your header needs to include an authcode


Damian Andre
Vaulter
Forum|alt.badge.img+23
  • Vaulter
  • December 18, 2022

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.' 

 


Forum|alt.badge.img+3
  • Author
  • Bit
  • December 19, 2022

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?


chrisknows
Byte
Forum|alt.badge.img+10
  • Byte
  • Answer
  • December 19, 2022

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.


Forum|alt.badge.img+3
  • Author
  • Bit
  • December 19, 2022

Got that, thanks @chrisknows 

Will try that out