chewbert1
Contributor
Contributor

Querying VRNI programmatically - api/search/query endpoint

I am encountering 401 unauthorized when I attempt to run queries using the API.  I may have a hostname when I start but not the vrni entity id.  I didn't see any methods to associate a hostname to it's corresponding VRNI entity ID.  What's the best way for me to extract useful information from VRNI programmatically if I'm coming in from an external source with only a hostname?

My request looks similar to the following:

{ method: 'get',
url: 'https://{{myVrniHost}}/api/search/query',
headers:
{ Authorization: 'NetworkInsight {{auth token}}',
'Content-Type': 'application/json',
Accept: 'application/json' },
params:
{ searchString: 'VM where DNS HostName = \'{{myHostName}}\'',
timestamp: 1627489359666,
timeRangeString: 'at Now',
maxItemCount: 10 } }

0 Kudos
2 Replies
smitmartijn
VMware Employee
VMware Employee

Hi,

All API calls to vRNI need authentication first, have a look at the API spec for /api/ni/auth/token.

By the way, /api/search/query takes in the internal query language of vRNI. In vRNI 6.3, you can use /api/search/query/ql for the 'regular' search queries, which you're using. Use that API.

0 Kudos
chewbert1
Contributor
Contributor

Thanks very much for your response, smitmartijn.  I didn't specify originally, but I am authenticating first with /api/ni/auth/token and then using that token in my Authentication header (with the format I specified in the original post).  If I attempt to use the /api/search/query/ql endpoint I get a 404.. but I suppose that's because I'm running 6.1.0

0 Kudos