VMware Cloud Community
rsingh13
Contributor
Contributor
Jump to solution

vRNI API

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

Tags (1)
1 Solution

Accepted Solutions
smitmartijn
VMware Employee
VMware Employee
Jump to solution

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

    }

View solution in original post

6 Replies
smitmartijn
VMware Employee
VMware Employee
Jump to solution

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?

0 Kudos
rsingh13
Contributor
Contributor
Jump to solution

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)

0 Kudos
smitmartijn
VMware Employee
VMware Employee
Jump to solution

Try this, the correct header is: Authorization: NetworkInsight AuthKey

0 Kudos
rsingh13
Contributor
Contributor
Jump to solution

Do you mean it should

headers = {

    "Content-Type":"application/json",

    "NetworkInsight AuthKey":AuthKey

    }

?

0 Kudos
smitmartijn
VMware Employee
VMware Employee
Jump to solution

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

    }

rsingh13
Contributor
Contributor
Jump to solution

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.

0 Kudos