Created
September 13, 2019 00:10
-
-
Save trisharia/66382494b083273d09a80f4e5dbe707f to your computer and use it in GitHub Desktop.
Get all vRA/vRA Cloud Project by name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// VMware vRealize Orchestrator action sample | |
// | |
// Get vRA/vRA Cloud project details in JSON format, given its name | |
// 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 | |
// name - string - Name of the project | |
// | |
// Return type: Any - JSON object of vRA/vRA Cloud project details | |
const opMethod = "GET"; | |
const opUrl = "/iaas/projects?$filter=name%20eq%20%27" + name.replace(/\s/g, "%20").replace(/\-/g, "%2D").replace(/\_/g, "%5F") + "%27"; | |
var headers = new Properties(); | |
headers.put("Authorization", "Bearer " + cspAuthToken); | |
var 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 projects (" + opResponse.statusCode + " Error). Details: " + opResponse.responseString; | |
} | |
var responseJson = JSON.parse(opResponse.responseString); | |
if (!responseJson.content || responseJson.content.length === 0) { | |
throw "No project found with name '" + name + "'"; | |
} | |
var project = responseJson.content[0]; | |
return project; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment