Question
How to access Versa Analytics REST APIs using CURL tool?
Solution:
Versa Analytics supports only token-based authentication and does not support basic authentication.
Analytics login API has changed for 21.1.1 release, now it uses cookies + X-CSRF-Token for authentication.
Step 1:
Follow these steps to access Versa Analytics:
curl -c cookies.txt -kv 'https://10.192.34.107/versa/analytics/auth/user'
Start authentication with the same session, and use the CSRF token from previous command You need to read the cookie with the session, but you need to update the cookie with the new authenticated session and updated CSRF as well
Step 2:
curl -b cookies.txt -c cookies.txt -k -d "username=admin&password=versa123" -H "X-CSRF-Token:<token>" https://10.192.34.107/versa/login
Now you can use the cookie in Readonly to pull data
e.g:
curl -b cookies.txt -kv -X GET 'https://10.192.34.107/versa/analytics/v1.0.0/data/provider/features/SDWAN/tenants'
Step 3: Don’t forget to logout
curl -b cookies.txt -kv -H "X-CSRF-Token:<token>" -X POST 'https://10.192.34.107/versa/logout'
Steps using Postman.
> Make a GET request to https://10.192.34.107:8443/versa/analytics/id or https://10.192.34.107:8443/versa/login ( Get req using no auth)
> Extract the CSRF token from the response headers (x-csrf-token)
> Make the usual POST request to the login API, but this time add the CSRF token to the request header (received from the above steps)