Yes, here is the code that I wrote for this.
import requests, os
import json
def GenrateToken():
BaseUrl = "https://vrniHost.corp/api/ni/auth/token"
creds = {
"username": os.environ.get('vrni_user'),
"password" : os.environ.get('A_PWD'),
"domain": {
"domain_type": "LDAP",
"value":"corp"
}
}
headers = {'Content-Type':'application/json'}
resp = requests.post(BaseUrl,headers=headers, data = json.dumps(creds), verify = False,)
key = resp.json()['token']
print key
return key
def GetSwitch(key):
AuthKey = key
BaseUrl = "https://vrniHost.corp/api/ni"
Uri = "/data-sources/cisco-switches"
headers = {
"Content-Type":"application/json",
"Authorization":AuthKey
}
CiscoResp = requests.get((BaseUrl+Uri),headers = headers, verify=False)
print CiscoResp.text
key = GenrateToken()
GetSwitch(key)