4 Replies Latest reply on Sep 24, 2019 1:43 PM by ericm24

    Create Transient RESTHost and RESTOperation.

    LaxmiRagi Novice


      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.

        • 1. Re: Create Transient RESTHost and RESTOperation.
          eoinbyrne Expert

          When I used the Transient RESTHost mechanism I had to use an existing inventory RESTHost as the template





          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



          • 2. Re: Create Transient RESTHost and RESTOperation.
            philippbck Novice

            // 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);


            1 person found this helpful
            • 3. Re: Create Transient RESTHost and RESTOperation.
              LaxmiRagi Novice

              Thank you so much its working...!

              • 4. Re: Create Transient RESTHost and RESTOperation.
                ericm24 Lurker



                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.