Point to vAPI Endpoint with JavaScript in vRO

This article covers a scenario where you need to point and work with vAPI endpoint entirely with JavaScript. It wasn’t as flawless as I expected and I spent quite some time to figure it out. Let’s jump in.

A while back Angel Iliev wrote 2 very detailed articles covering vAPI and working with tags in vSphere:
vSphere 6 Automation with vRO 7 – Tags and vAPI – Part I – The Virtualist
vSphere Automation with vRO 7 – Tags and vAPI – Part II – The Virtualist

Usually, when using the vAPI endpoint from a workflow, you can add it as an attribute with a predefined value so the end users would not need to select it at run time. That’s really handy for all types of known or constant attributes. However, recently I had to work with vSphere tags only via vRO action element. As you know, you can’t have an attribute with predefined value in an action element as you do in a workflow. So basically, I needed variable pointing to my VAPIEndpoint object.

First stop of course – the API explorer. Expanding the vAPI plug in, seems like the VAPI Manager class has a function called findEndpoint, which would give me exactly what I’m looking for:
It accepts single argument of type string which should be the vAPI endpoint URL. Great, that’s easy. The vAPI endpoint URL is in the format: https://<vCenter FQDN or IP>:443/api
Now passing this as argument of the findEndpoint function and printing the variable to see what we got in return:

And here is the result:
Well, null was not what I expected. I started different approach – reverse engineering. I added an attribute of type VAPI:VAPIEndpoint to the workflow and selected my endpoint as a value:
Looking again at the API explorer, the VAPIEndpoint class has property named endpointUrl which will return the URL as a string – exactly what the findEndpoint function needed.
I was interested what would it look like, so first just printed it out:

Here is the result:
Exactly what I’ve passed to the findEndpoint function before without success.

After some time spent with google trying to find something relevant, I came back to vRO and printed out the entire VAPIEndpoint object:

And the result:
Here I noticed something in the square brackets containing the “known properties”: ENDPOINT–https___192.168.1.204_443_api

It does contain the vAPI endpoint URL in a little bit weird format, but that was enough for me to give it a try:

And voila:
Now I got what I needed and I was able to continue working on my action element.

 

I find the description of the findEndpoint function misleading, as using the URL would not get you any result. My current setup is:
vRO – 7.1.0
vAPI plugin – 7.1.0

I hope this would save you the time I spent wondering what is wrong. If you notice different behavior in older or newer versions of the plugin please share!

The following two tabs change content below.

Ivaylo Ivanov

Ivaylo has 5 years of professional IT experience. Most of it in server administration area, network and virtualization technologies. From 2014 he specializes in VMware products family. He holds VCP-DCV, VCAP-DCA and VCP-CMA certifications. vExpert 2016/2017

About Ivaylo Ivanov

Ivaylo has 5 years of professional IT experience. Most of it in server administration area, network and virtualization technologies. From 2014 he specializes in VMware products family. He holds VCP-DCV, VCAP-DCA and VCP-CMA certifications. vExpert 2016/2017
Bookmark the permalink.

Leave a Reply