Thus far, I've been building workflows that call out to powershell commands that reach out to a restful API that accepts and responds with JSON.
and those workflows work very well as is with a powershell module but there's some overhead there that comes with the use of the powershell module and reaching out to a powershell host locally or remotely.
So that got me thinking about being able to communicate directly with the API from within vRO. Are there any examples of how to make http/https calls directly?
thank you.
Start looking around at the REST and SOAP plugin and you should be able to find some examples for connection to all sorts of different systems from CMDB to IP ect
Thank you.
Is there no way to do this natively?
Is there an HTTP/S library built in that might allow me to get/post requests and then parse out the JSON that's received?
thank you again.
Well, there is a built-in scripting class URL which allows you to send basic GET/PUT/POST/DELETE requests, but it is quite primitive (eg. you don't have access to request headers). Take a look at it in vRO API Explorer to check if it suits your needs.
As for the parsing out the received JSON - you don't need this; Javascript works natively with JSON. Take a look at eg. JSON.stringify() and JSON.parse()
For calling REST APIs, you will need to add the REST HOST using REST plugin and then you can perform the operations like below:
var request = this.host.createRequest(method, requestUrl, body);
if (headers) {
for (var key in headers) {
if (headers.hasOwnProperty(key))
request.setHeader(key, headers[key]);
}
}
var response = request.execute();
Where host will be your REST HOST object, which you can obtain by iterating all the rest hosts
var registeredHosts = Server.findAllForType('REST:RESTHost');
for (var i=0; i<registeredHosts.length; i++) {
if (registeredHosts[i].name == <YOURHOSTNAME>){
registeredHost = registeredHosts[i];
}
}
Thank you for that information. I would definitely need to modify the headers as part of this API access! I'll check out the Rest plugin.