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
privateRESTRequestExecute(strMethod:string,strFQDN:string,strUri:string,strUserName:string,strPassword:string,objContentJson:any)
letarrRESTAuthenticationParams:string[]= ['Shared Session',strUsername,strPassword];
letobjRESTAuthentication:RESTAuthentication=RESTAuthenticationManager.createAuthentication('Basic',arrRESTAuthenticationParams);
letobjRESTHost:RESTHost=RESTHostManager.createHost("TransientHost");
objRESTHost=RESTHostManager.createTransientHostFrom(objRESTHost);
objRESTHost.url="https://"+strFQDN;
letobjRESTRequest:RESTRequest=objRESTHost.createRequest(strMethod,strUri,objContentJson);
objRESTRequest.contentType="application/json";
letobjRESTResponse:RESTResponse=objRESTRequest.execute();
if (objRESTResponse.statusCode===200)
{
letobjProperties:Properties=objRESTResponse.getAllHeaders();
letarrKey:string[]=objProperties.keys;
arrKey.forEach((strKey:string):void=>{
System.log(`REST Response Header${strKey}:${objProperties.get(strKey)}`);
letarrHeaderValues: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)
{
letobjRESTResponseBody: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.
