0 Replies Latest reply on May 18, 2018 1:37 AM by bigfoot48

    vRealize Network Insight - API - Powershell - Convert search to API json format

    bigfoot48 Lurker



      I'm trying to convert a search in vRNI to a search in the API with the same results.
      But I'm experiencing some difficulties to get the same response results from the API in understandable human format.


      I need to measure all the Edge's internet traffic and i came up with this search:

      • total(Total Network Traffic) of vnic '[vse-ABC-EDGE-01 (GUID)-0]-[Network adapter 1]' where vm = vse-ABC-EDGE-01

      This example gives me the information i need but i cant get it converted to Powershell to get the same request.


      The API documentation doesn't explain how you can convert a search in vRNI to an API search.

      I wrote the following PowerShell script:



      # Set the correct TLS protocol
      [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
      # Address and login info
      $baseurl = "https://vRNI.someserver.com"
      $user = "admin@yourdomain.local"
      $pass = 'ReallyDifficultPassword'
      # Json format for aquiring token
      $body = '{
       "username": "'+$user+'",
       "password": "'+$pass+'",
       "domain": {
       "domain_type" : "LDAP",
       "value" : "yourdomain.local"
      # Getting token for api queries
      $url = $baseurl + "/api/ni/auth/token"
      $auth = Invoke-RestMethod -Method POST -Uri $url -Body $body -ContentType "application/json"
      #converting the token 
      $token = $auth.token
      $headers = @{"Authorization"="NetworkInsight $token"}
      # First run to get VMs
      $url = $baseurl + "/api/ni/entities/vms"
      $entities = Invoke-RestMethod -Method GET -Uri $url -ContentType "application/json" -Headers $headers
      # Testing search functionality
      $body = @{
       "entity_type"= "VirtualMachine"
       "filter"=  "default_gateway is set"
      $url = $baseurl + "/api/ni/search"
      $entities = Invoke-RestMethod -Method POST -Uri $url -Body ($body | ConvertTo-Json) -ContentType "application/json" -Headers $headers
      # Find VMs with name starting with 'vse'
      $body = @{
       "entity_type"= "VirtualMachine"
       "filter"=  "host.name like vse*"
      $url = $baseurl + "/api/ni/search"
      $filter = Invoke-RestMethod -Method POST -Uri $url -Body ($body | ConvertTo-Json) -ContentType "application/json" -Headers $headers


      Does anybody knows how to convert a search or know where to find that kind of information?