VCF Automation Blog

from Stefan Schnell

Get Detailed Information about an Action via API


/**
 *
 * @module de.stschnell
 *
 * @version 0.1.0
 *
 * @param {string} in_userName
 * @param {SecureString} in_password
 * @param {string} in_moduleName
 * @param {string} in_actionName
 *
 * @outputType {Properties}
 *
 * @description Detects detailed information of an action
 */

function getActionInformation(
  in_userName,
  in_password,
  in_moduleName,
  in_actionName
) {

// Begin ---------------------------------------------------------------

/**
 * @name getActionInformation
 *
 * @author Stefan Schnell <mail@stefan-schnell.de>
 * @license MIT
 */

function _main(userName, password, moduleName, actionName) {

  var bearerToken = System.getModule("de.stschnell").getBearerToken(
    userName,
    password
  );

  if (!bearerToken) {
    throw new Error("No Bearer token");
  }

  var httpRestHost = RESTHostManager.createTransientHostFrom(
    RESTHostManager.createHost("dynamicRequest")
  );
  httpRestHost.operationTimeout = 60;
  httpRestHost.connectionTimeout = 30;
  httpRestHost.hostVerification = false;
  httpRestHost.url = "https://" + System.getModule("de.stschnell").getFQDN();
  // Orchestrator > Orchestrator Server API > action-controller
  var request = httpRestHost.createRequest(
    "GET",
    "/vco/api/actions/" + moduleName + "/" + actionName
  );
  request.contentType = "application/json";
  request.setHeader("Authorization", "Bearer " + bearerToken);
  var response = request.execute();
  if (response.statusCode === 200) {
    var actionBaseData = JSON.parse(response.contentAsString);
    return actionBaseData;
  }
  return null;

}

// Main
if (
  String(in_userName).trim() !== "" &&
  String(in_password).trim() !== "" &&
  String(in_moduleName).trim() !== "" &&
  String(in_actionName).trim() !== ""
) {
  return _main(in_userName, in_password, in_moduleName, in_actionName);
} else {
  throw new Error(
    "in_userName, in_password, in_moduleName or in_actionName \
     argument can not be null"
  );
}

// End -----------------------------------------------------------------

}

vcf automation orchestrator action to get details of an action