How to use a Transient RESTHost in Orchestrator

by Simon Sparks · January 17, 2026

To use this function add it to the class library file named vCenterServerService.ts

GitHub Repository: https://github.com/SimonSparksUK/Orchestrator

Filename: vCenterServerService.ts

Function: RESTRequestExecute

private RESTRequestExecute(strMethod:string, strFQDN:string, strUri:string, strUserName:string, strPassword:string, objContentJson:any)

let arrRESTAuthenticationParams: string[] = ['Shared Session', strUsername, strPassword];

let objRESTAuthentication: RESTAuthentication = RESTAuthenticationManager.createAuthentication('Basic', arrRESTAuthenticationParams);


let objRESTHost: RESTHost= RESTHostManager.createHost("TransientHost");
objRESTHost = RESTHostManager.createTransientHostFrom(objRESTHost);
objRESTHost.url = "https://" + strFQDN;

let objRESTRequest: RESTRequest= objRESTHost.createRequest(strMethod, strUri, objContentJson);
objRESTRequest.contentType = "application/json";

let objRESTResponse: RESTResponse= objRESTRequest.execute();

if (objRESTResponse.statusCode === 200)
{
  let objProperties: Properties = objRESTResponse.getAllHeaders();
  
  let arrKey: string[] = objProperties.keys;
  
  arrKey.forEach((strKey: string): void => {
      System.log(`REST Response Header ${strKey}: ${objProperties.get(strKey)}`);
  
      let arrHeaderValues: string[] = objRESTResponse.getHeaderValues(strKey);
  
      System.log(`REST Response Header ${strKey}: ${JSON.stringify(arrHeaderValues, null, 4)}`);
  });

  // If you know the schema of the return then define a type or interface and replace "any".

  System.log("REST Response Content Length: " + objRESTResponse.contentLength);
  
  if (objRESTResponse.contentLength > 0)
  {
    let objRESTResponseBody: any = JSON.parse(objRESTResponse.contentAsString);
    
    // Process the Json
  }
}
else
{
  System.log("Something went wrong...");
}

Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like