Created
March 27, 2023 08:03
-
-
Save imtrinity94/5c0eabe54bd292cac1d35acda96cab01 to your computer and use it in GitHub Desktop.
Generate vRA Bearer Token using vRO Action
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
if(arguments.callee.name.substr(6)) System.setLogMarker("ACTION: "+arguments.callee.name.substr(6)); | |
var vraRestHost = vraHost.createRestClient(); | |
System.log("vRA hostname: "+vraHost.name); | |
var loginObj = {}; | |
loginObj.domain = domain; | |
loginObj.password = password; | |
loginObj.username = username; | |
var loginBody = JSON.stringify(loginObj); | |
var operationUrl = "/csp/gateway/am/api/login"; | |
var request = vraRestHost.createRequest("POST", operationUrl, loginBody); | |
request.setHeader("Content-Type", "application/json"); | |
var response = vraRestHost.execute(request); | |
if (response.statusCode != 200) { | |
System.warn("Request failed with status code " + response.statusCode); | |
} else { | |
System.log("Status code: "+response.statusCode); | |
var res = JSON.parse(response.contentAsString); | |
var token = res.cspAuthToken; | |
System.log("Token generated successfully"); | |
return token; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment