6 Replies Latest reply on Mar 17, 2019 4:37 AM by rsingh13

    vRNI API

    rsingh13 Lurker

      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?



        • 1. Re: vRNI API
          smitmartijn Hot Shot
          vExpertVMware Employees



          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?

          • 2. Re: vRNI API
            rsingh13 Lurker



            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",




                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 = {




                CiscoResp = requests.get((BaseUrl+Uri),headers = headers, verify=False)

                print CiscoResp.text



            key = GenrateToken()



            • 3. Re: vRNI API
              smitmartijn Hot Shot
              vExpertVMware Employees

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



              • 4. Re: vRNI API
                rsingh13 Lurker

                Do you mean it should


                headers = {


                    "NetworkInsight AuthKey":AuthKey




                • 5. Re: vRNI API
                  smitmartijn Hot Shot
                  VMware EmployeesvExpert

                  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 = {


                      "Authorization": "NetworkInsight " AuthKey


                  • 6. Re: vRNI API
                    rsingh13 Lurker

                    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.