vRO and JavaScript

Recently I spent what I think was way too much time in cobbling together about a dozen lines of javascript code so vRO could make REST calls in automating something. I mainly did this by reverse engineering someone else’s script and trial and error. I’d like to know the foundations of this better so that next time it won’t be so painful. Granted this was my first thing I’ve written in javascript, but I’m clueless on javascript practices, the REST parameters/content, and tying this all together with what vRO expects. Outside of VMware documentation, if anyone has any suggested material I’d appreciate it.

View Reddit by derpjutsuView Source


To see the full content, share this page by clicking one of the buttons below

Related Articles


  1. I’ve found the built in workflows and online javascript resources to be useful. The annoyance that comes up sometimes is that the javascript implementation in vRO doesn’t appear to be recent or fully featured, so an online resource may talk about doing something in javascript that you simply can’t do the same way in a vRO workflow.

  2. Every REST endpoint is a little bit different so it’s always interesting to solve.

    If you have only a few straightforward operations you will need to use in your workflows, I would define them with the vRO configuration flows, and you can auto-generate some workflows from those operationsthat will help you get started.

    But, I find for development it is faster to write a few lines of code and make it easy to tweak in the scripts, rather than running workflows to make minor changes each time.

    So if you have ‘restHost’ as one of your inputs of type REST:RESTHost:

    var restResponse = restHost.createRequest(“GET”, “/api/v2/something”, “{}”).execute()
    System.log(“Status Code: “+restResponse.statusCode)
    System.log(“Response: ” + restResponse.contentAsString)

    // Convert the JSON response to an object
    var responseObject = JSON.parse(restResponse.contentAsString)
    // Convert the object to a JSON string
    var responseString = JSON.stringify(responseObject)

    JSON parsing and creating objects is probably the most useful thing to know when working with the REST Plugin.


    This blog has a lot of posts about using REST operations and just vRO in general.

    I’m happy to answer questions though!

Leave a Reply