Posted on September 26, 2019 4:27 pm
 |  Asked by Jose Pichardo
 |  119 views
0
0
Print Friendly, PDF & Email

Hello,

Im using a REST API Client called Postman to send APIs to CVP. I’m receiving a “401” Response due to failed authentication. I was able to make the API call using the FQDN/web/api/ but I noticed it works only when a user is logged in to the CVP console. If no user is logged in then the API call fails with the failed authentication error. Also, I noticed when I used Postman or any other REST client the CVP console user was logged out automatically.

Im doing something simple (a new label). I added the content-type and the authentication headers to the API call.

Thanks in advance.
Jose P.

0
Posted by Tyler Conrad
Answered on September 26, 2019 4:37 pm

Hi Jose,

You’ll need to generate a token before you can successfully run commands against CVP. This is passed in the headers as json using “session_id” as the key, and the token as the value.

If you want to generate a token, you’ll want to perform an http post against /cvpservice/login/authenticate.do with a body of {“userId”:username,”password”:password}, which will then generate the token which can be appended to all your requests as a cookie.

Here’s a quick and dirty example of using the CVP API from start to finish:
https://github.com/brokenpackets/API_Training/blob/master/CVP_Basic.py

Hope this helps,
-T

0
Posted by Tamas Plugor
Answered on September 26, 2019 4:38 pm

Hi Jose,

With Postman, you can create a POST for “/cvpservice/login/authenticate.do” and inside the body put the username and password in a dictionary like below:

{
“userId”: “cvpadmin”,
“password”: “arastra”
}

this should save the cookies and you can then do GETs in another tab.

Using python you can use the requests library, authenticate, save the cookies and then use those cookies in subsequent calls (See txt attached) or you could also use requests.Session() as well.

Hope this helps,
Tamas

Post your Answer

You must be logged in to post an answer.