From 84924248fbc23bfd40bd6347bc8d9dedeacfcf81 Mon Sep 17 00:00:00 2001 From: John Bowdre <61015723+jbowdre@users.noreply.github.com> Date: Tue, 14 Jun 2022 08:51:53 -0500 Subject: [PATCH] Create vraExecute.js --- .../com.virtuallypotato.utility/vraExecute.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Orchestrator/Actions/com.virtuallypotato.utility/vraExecute.js diff --git a/Orchestrator/Actions/com.virtuallypotato.utility/vraExecute.js b/Orchestrator/Actions/com.virtuallypotato.utility/vraExecute.js new file mode 100644 index 0000000..5a2a5c0 --- /dev/null +++ b/Orchestrator/Actions/com.virtuallypotato.utility/vraExecute.js @@ -0,0 +1,23 @@ +/* JavaScript: vraExecute action + Executes an action against a vRA REST endpoint. + Inputs: token (string), method (string), uri (string), content (string) + Return type: string +*/ +var host = System.getModule("com.virtuallypotato.utility").getConfigValue("vPotato", "Endpoints", "vRAHost").host; +System.log(host); +if (content) { + var request = host.createRequest(method, uri, content); +} else { + var request = host.createRequest(method, uri); +} +request.setHeader("Content-Type", "application/json"); +request.setHeader("Authorization", "Bearer " + token); +var response = request.execute(); +var statusCode = response.statusCode; +var responseContent = response.contentAsString; +if (statusCode > 399) { + System.error(responseContent); + throw "vraExecute action failed, status code: " + statusCode; +} + +return responseContent;