How to retrieve a script Resource from vRO via curl

I recently spent time with a customer doing a vRO workshop with them. During the course of the workshop, I was asked how you could retrieve a script that had been stored as a resource element on a vRO server using curl. Well, I had never done that before so I set out to figure it out and was able to provide the solution before I left! Throughout this article, I will be using a vRA 7.2 embedded vRO. The biggest difference here is only the port that we use to access the API. For embedded, it is 443 and standalone vRO uses 8281.

Check the API - resource-controller

Whenever calling vRO from any language, you must reference the API documentation to help identify the appropriate REST URL to call. So, my first stop was to visit the /vco/api/docs URL of the server and look for Resources.

Hmmm… looking at the screenshot above, and the few other operations below, it seems that the /api/resources/{id} is the closest I’ll get to retrieving the script. Unfortunately, nothing in that doc indicates the possibility of retrieving the actual file or the contents of the file. Not looking good right now.

Ok, well, we obviously need the ID of the resource element we wish to retrieve. Let’s launch our vRO Client and get the ID of our script.

vRO Client - Resource Element - setupCA.ps1

Hmmmm…. well, There doesn’t appear to be an ID visible for our resource elements! Bummer!

I guess we go back to the API explorer - hopefully, we can filter by name.

Be sure to make note of the Mime type - we’ll be needing that later too!

API Documentation - Postman Verify

When you’re uncertain as to how to use the API, make sure to review the Developing a Web Services Client for VMware vRealize Orchestrator official documentation page. In particular, the page I need is the Apply Filters page as it shows you how to query vRO for the particular resource you are looking for. In my case, it is the setupCA.ps1 Resource Element so, my GET URL needs to be:

1
https://{{vra-fqdn}}/vco/api/catalog/System/ResourceElement?conditions=name~setupCA.ps1

As we can see in the image above, the query works! and we can see the id for that Resource Element is: 2706d28b-e6ca-45da-acd9-8ccff2228252

Moment of Truth - Postman Results

Ok, we now know the following:

  • ID of the Resource Element we wish to retrieve
  • The Mime Type of the script
  • The script name
  • The REST API URL and Method (GET) to retrieve the script

Let’s see if this works! Use Postman for your quick testing…

  • Set the URL to https://{{vra-fqdn}}/vco/api/resources/2706d28b-e6ca-45da-acd9-8ccff2228252/ where {{vra-fqdn}} is your vRA/vRO server’s FQDN and port (if vRO standalone), and that string after resources is the discovered id of the script you wish to get from the server
  • Set the Operation Method to GET
  • Set the header: Accept: application/octet-stream <– this should be the Mime Type of the Resource element as we saw in the vRO client. Click SEND
  • Success should be expected as seen in the returned body, we have the script contents!

Putting it all together as a curl command

Ok, we should be all set now! We’ve done all of the exploratory work needed to discover the correct URL, Methods, ID, etc…

So, based on the information we retrieved above, this is the following curl command you would use:

1
curl -k --header 'Accept: application/octet-stream' --header 'Authorization: Basic REDACTED' 'https://{{vra-fqdn}}/vco/api/resources/2706d28b-e6ca-45da-acd9-8ccff2228252' -o setupCA.ps1

Now, for those of us that may not be as familiar with curl, let’s break down the call….

curl -> the command we are issuing

-k -> tells curl to ignore invalid/self-signed certificates

–header -> sets the headers as needed. In this case, we use the switch twice. Once to set the Accept Header and once to set the Authorization header. (TIP: You can easily get your Authorization header in Postman!!) After specifying the headers, you specify the URL you wish to query

-o –> sets the output file name

setupCA.ps1 -> the name of the output file (Ideally, you would use the same name as the script name defined for the Resource Element, but you can actually use whatever name you like!)

Summary

Even though the vRO Client does not provide the ID for resource elements, it only takes a tiny bit of research and a quick call with Postman to get the needed info. Once you have it, you can code your curl command into scripts, vRA software components, etc… as needed!