VMware Cloud Community
RobBastiaansen_
Hot Shot
Hot Shot

how to authenticate for rest api with vCenter 6.5 appliance

Hello,

vCenter Appliance 6.5 has a feature to create a backup that can be restored with the installer gui. To create this backup one must access the appliance portal at port 5480. I would like to automate and schedule that backup. It can be accessed with the API's from the SDK. It must be possible to execute this via REST API. A bash sample is documented:

https://pubs.vmware.com/vsphere-65/index.jsp#com.vmware.vsphere.vcsapg-rest.doc/GUID-222400F3-678E-4...

I have tried to authenticate to vCenter to invoke a rest operation from Orchestrator but I have not had any success.

I think that I can't use the right authentication mechanism, when I try to invoke the REST operation i get a 401 error. I have tried the basic authentication and I have looked at using the other mechanisms that are listed when adding a REST host in Orchestrator but can't figure out what to use.

If anyone has earlier connected with vCenter Appliance via REST and could share how to authenticate that information would be greatly appreciated.

0 Kudos
1 Reply
iiliev
VMware Employee
VMware Employee

Here is some sample vRO JS code that seems to work in my 6.5 environment. The workflow input parameter is the variable host (of type REST:RESTHost) configured with Basic authentication.

var vcenter = "10.20.160.200";

var user = "vcuser1";

var pass = "vcpass1";

var request = host.createRequest("POST", "https://" + vcenter + "/rest/com/vmware/cis/session", "");

var response = request.executeWithCredentials(user, pass);

var sessionid = JSON.parse(response.contentAsString).value;

System.log("response code: " + response.statusCode);

System.log("response body: " + response.contentAsString);

System.log("sessionid: " + sessionid);

var taskjson =

{ "piece":

      {

          "location_type":"FTP",

          "comment":"Automatic backup",

          "parts":["seat"],

          "location":"ftp://10.20.6.12/backup/",

          "location_user":"ftpuser1",

          "location_password":"ftppass1"

      }

}

request = host.createRequest("POST", "https://" + vcenter + "/rest/appliance/recovery/backup/job", JSON.stringify(taskjson));

request.setHeader("Accept", "application/json");

request.setHeader("Content-Type", "application/json");

var response = request.executeWithCredentials(user, pass);

var jobid = JSON.parse(response.contentAsString).value.id;

System.log("response code: " + response.statusCode);

System.log("response body: " + response.contentAsString);

System.log("backup job id: " + jobid);

var status = "INPROGRESS";

while (status == "INPROGRESS") {

  System.sleep(10000);

  request = host.createRequest("GET", "https://" + vcenter + "/rest/appliance/recovery/backup/job/" + jobid, "");

  request.setHeader("Accept", "application/json");

  response = request.executeWithCredentials(user, pass);

  status = JSON.parse(response.contentAsString).value.state;

  System.log("response code: " + response.statusCode);

  System.log("status: " + status);

  System.log("response body: " + response.contentAsString);

}

System.log("Completion status: " + status);

0 Kudos