Hi,
I am facing problem while creating transient RESThost and RestOperation.
Execute a transient RESTOperation for a transient RESTHost - Samples - VMware {code}
While executing above reference code as it is below error occurs
Unable to create object : RESTHost : com.vmware.o11n.plugin.rest.RESTHost
My Inputs:
URL : https://myhost/myapp/api/
user: username
password : pass2345
Please help me to understand where am i doing mistake.
Thnak you.
// Create REST Request
var restHost = RESTHostManager.createHost("dynamicRequest");
httpRestHost = RESTHostManager.createTransientHostFrom(restHost);
httpRestHost.operationTimeout = 60;
httpRestHost.connectionTimeout = 30;
httpRestHost.hostVerification = false;
httpRestHost.url = requestHostUrl;
var request = httpRestHost.createRequest(requestMethod, requestTemplateUrl, requestBody);
// Basic authentication:
var authParams = ['Shared Session', username, password];
var authenticationObject = RESTAuthenticationManager.createAuthentication('Basic', authParams);
httpRestHost.authentication = authenticationObject;
// Set Content Type
request.contentType = requestContentType;
if (closeConnection == true){
request.setHeader("Connection", "Close")
}
// Execute REST Request
System.log("REST Request: " + requestMethod + " " + request.fullUrl);
var response = request.execute();
// Output
statusCodeAttribute = response.statusCode;
System.log("REST Response Status Code: " + statusCodeAttribute);
responseAsString = response.contentAsString;
if(logResponseOutput == true){
System.log("REST Response Content: " + responseAsString);
}
When I used the Transient RESTHost mechanism I had to use an existing inventory RESTHost as the template
e.g.,
var myURL = "https://myhost/myapp/api";
var transientRESTHost = RESTHostManager.createTransientHostFrom(inventoryRESTHost);
transientRESTHost.url = myURL;
The class document for that method - vRO API Explorer by Dr Ruurd and Flores of ITQ - shows that an existing RESTHost instance is used as a template / prototype
HTH
// Create REST Request
var restHost = RESTHostManager.createHost("dynamicRequest");
httpRestHost = RESTHostManager.createTransientHostFrom(restHost);
httpRestHost.operationTimeout = 60;
httpRestHost.connectionTimeout = 30;
httpRestHost.hostVerification = false;
httpRestHost.url = requestHostUrl;
var request = httpRestHost.createRequest(requestMethod, requestTemplateUrl, requestBody);
// Basic authentication:
var authParams = ['Shared Session', username, password];
var authenticationObject = RESTAuthenticationManager.createAuthentication('Basic', authParams);
httpRestHost.authentication = authenticationObject;
// Set Content Type
request.contentType = requestContentType;
if (closeConnection == true){
request.setHeader("Connection", "Close")
}
// Execute REST Request
System.log("REST Request: " + requestMethod + " " + request.fullUrl);
var response = request.execute();
// Output
statusCodeAttribute = response.statusCode;
System.log("REST Response Status Code: " + statusCodeAttribute);
responseAsString = response.contentAsString;
if(logResponseOutput == true){
System.log("REST Response Content: " + responseAsString);
}
Thank you so much its working...!
Hello,
I am facing similar situation, however, I need to use Cert-Based Auth, and send the cert that is on the current box.
Basically the the code below usese "basic auth".
var authParams = ["Shared Session", user, pw];
var authObject = RESTAuthenticationManager.createAuthentication("Basic", authParams);
What would be the parameters & setup to call .createAuthentication(..) and specify cert-based auth?
It looks like this is possible, because when you evoke the "Add a REST Host" action, you have the option to specify "The Private Key Entry For certificate based authentication", which allows me to select a cert that has been on-boarded to this machine.
Any help would be greatly appreciated.
QQ:
on this line:
var request = httpRestHost.createRequest(requestMethod, requestTemplateUrl, requestBody);
What is the requestTemplateUrl supposed to be? I can find no documentation on this anywhere.
requestMethod = GET | POST | DELETE | PATCH...etc
requestTemplateUrl = the api call; /api/vco/someAPIendpoint
requestBody = the document to send [used for POST | PATCH].. for GET | DELETE just make it null
This doesnt seem to work anymore since upgrading to 8.10.
Does it still work for anyone?