Hi Members
I am using vRNI api calls for listing the available data sources. I can view/add data sources using GUI but I cant do it with API call. I am getting {"code":401,"message":"HTTP 401 Unauthorized"} in response?
Any help?
Thanks
Rsingh13
No. It's exactly as I mentioned, the header should be: "Authorization: NetworkInsight YourAuthenticationToken"
This might translate to the following code, but I'm not sure if the syntax is correct.
headers = {
"Content-Type":"application/json",
"Authorization": "NetworkInsight " AuthKey
}
Hi,
What is the exact API call you're executing? Are you logged in via /api/ni/auth/token and then using the returned authentication token in the headers for the data source API call?
smitmartijn
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)
Try this, the correct header is: Authorization: NetworkInsight AuthKey
Do you mean it should
headers = {
"Content-Type":"application/json",
"NetworkInsight AuthKey":AuthKey
}
?
No. It's exactly as I mentioned, the header should be: "Authorization: NetworkInsight YourAuthenticationToken"
This might translate to the following code, but I'm not sure if the syntax is correct.
headers = {
"Content-Type":"application/json",
"Authorization": "NetworkInsight " AuthKey
}
This worked, Thank you very much.
Is there a document that helps with these small details? Unfotunately I couln't find anything by myself and api explorer doesn't provide this.