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

b_600_0_16777215_01_images_media_1492131146364_lg.png

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

b_600_0_16777215_01_images_media_1492131542917_lg.png

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

b_600_0_16777215_01_images_media_1492132170261_lg.png

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:

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

b_600_0_16777215_01_images_media_1492132829832_lg.png

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...

  1. 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
  2. Set the Operation Method to GET
  3. 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
  4. 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:

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!

Search

Book Shelf

 
Experts Exchange

NUC Lab Kit

Below are my thoughts for a vSAN nuc lab. Since I already have cables, not including them here. I ordered (and received by Nov 30, 2016)
3 x nuc, 3 x 32GB Crucial mem, 3 x Toshiba NVMe drive, 3 x Startech USB to GB NIC, and 3 x Crucial 1TB SSD. I've also been very happy with my Cisco SG300-10 so I bought one more since my existing one only has one port available. Each of the items listed here are linked below - all were purchased using the provided links below.
single NIC (See this post for details on using the USB -> GB NIC item listed below

I stayed with the i5 for the power consumption and form factor vs. the i7 Skull Canyon ;)