Skip to content

Instantly share code, notes, and snippets.

@trisharia
Last active September 12, 2019 23:35
Show Gist options
  • Save trisharia/ffb8f3a04760932803bf712b37cb53b7 to your computer and use it in GitHub Desktop.
Save trisharia/ffb8f3a04760932803bf712b37cb53b7 to your computer and use it in GitHub Desktop.
Get all vRA Cloud Blueprint Requests
// VMware vRealize Orchestrator action sample
//
// Get an array of all vRA/vRA Cloud blueprint request details in JSON format
// Assumes the presence of action System.getModule("com.vmware.pso.rest").executeTransientRESTOperation
// Obtain the action here: https://gist.github.com/trisharia/7b62fcdf12600511b3d7e9b635981b2c
//
// For vRA Cloud 7.0+ and vRA 8.0+
//
// Action Inputs:
// cspBaseUrl - string - Base URL for connecting to VMware Cloud Services RESTful API
// e.g., https://api.mgmt.cloud.vmware.com
// cspAuthToken - string - VMware Cloud Services bearer token
// Get this token by running the following action first: https://gist.github.com/trisharia/4262427728b9ca2f22f76c39a5521768
//
// Return type: Array/Any - all vRA/vRA Cloud blueprint request details in JSON format
const opMethod = "GET";
var allBpRequests = [];
var opUrl = "/blueprint/api/blueprint-requests";
var opResponse;
var responseJson;
var content;
var totalCount;
var headers = new Properties();
headers.put("Authorization", "Bearer " + cspAuthToken);
do {
opResponse = System.getModule("com.vmware.pso.rest").executeTransientRESTOperation(
cspBaseUrl,null,null,opMethod,opUrl,null,headers,null,null);
if (opResponse.statusCode >= 400) {
throw "Failed to get blueprint requests (" + opResponse.statusCode + " Error). Details: " + opResponse.responseString;
}
responseJson = JSON.parse(opResponse.responseString);
if (!totalCount) totalCount = responseJson.count;
content = responseJson.objects;
//System.debug("Batch length: " + content.length);
allBpRequests = allBpRequests.concat(content);
opUrl = responseJson.nextPageLink;
//System.debug("nextPageLink: " + opUrl);
//System.debug("Count so far: " + allBpRequests.length);
} while (opUrl)
System.log("Total blueprint requests: " + totalCount);
System.log("Total blueprint requests obtained: " + allBpRequests.length);
return allBpRequests;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment