• Using the CloudVision API with Service Accounts

Print Friendly, PDF & Email


With the release of CloudVision Portal 2020.3, you have the ability to create Service Accounts. I won’t show you how to create a Service Account, but you can go to this TOI to read about that. This article will show you how to use Service Account Tokens in Python and cURL for API calls.

Platform Compatibility

This applies to both CVaaS and on-premise installations.

How To

Using a Service Account Token allows you to bypass the standard authentication process when making API calls. It also allows you to create a local “account” on CloudVision that doesn’t depend on outside authentication mechanisms.

When you create a Service Account, CloudVision will give you a token for that account. Copy that token; that is what you will use to authenticate with CloudVision. We will present that token as an Authorization header for every request we make to CloudVision; this is different from using a normal account. When we use a normal account, we need to authenticate and create a session; that process is not needed with a token.


With cURL, we can use the -b or -H flag in the command.

curl -b access_token=${<Your Token>} ...
curl -H 'Authorization: Bearer ${<Your Token>}' ...



In this Python example, I will be using the library. cvprac. cvprac It is a library created by Arista to make it easier to interface with CloudVision.

from cvprac.cvp_client import CvpClient
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
import requests.packages.urllib3
token = '<Your Token>'
clnt = CvpClient()
clnt.connect(nodes=['<CloudVision>'], username='',password='',api_token=tok)
{'version': '2020.3.0'}

Using the library allows you only to need to enter the token once when creating the session to CloudVision


In this python example, I will be using the library requests

import request
cvp = requests.Session()
url = "https://<CloudVision>"
token = "<Your Token>"
api = "<API Path>"
response = cvp.get(url + api, verify=False, headers={"Authorization": "Bearer {}".format(token)})

We can now use the variable response to get the return json from CloudVision. Remember, you will need to use the token for every single request sent to CloudVision.


Additional Resources






Get every new post on this blog delivered to your Inbox.

Join other followers: