I am trying to call a vChargeBack API for getting information on vCenter server. I am having issues with this.
I have to pass request as XML data in request body. And also I have to pass version as URL parameter. The code I have written is
$xmlfile=simplexml_load_file('login.xml');
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$xmlfile);//Passing XML file as POST field
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_URL,"https://xx.xx.xx.xx/vCenter-CB/api/login");//Setting URL
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch , CURLOPT_SSL_VERIFYPEER , false );//Since I am requesting https
curl_setopt($ch , CURLOPT_SSL_VERIFYHOST , false );//Since I am requesting https
curl_setopt($ch, CURLOPT_HTTPHEADER, array ('Accept: ' . $this->acceptType ));
$response=curl_exec($ch);//Getting response
$responseInfo=curl_getinfo($ch);//Getting response headers
When I execute, I have 400 Bad Request response. What I noticed is I am not sending version as URL parameter.
It should be
Name : version
value : 1.5.0
I am not knowing how to send this version as URL parameter. Should I send that as POSTFIELD then how should i send xml file as a request body.
Please help me…
Regards,
Srinath
The Chargeback interface is not RESTful. It’s an XML portal with resources at given endpoints defined by the documentation. To log in, fill in the
API_NAMESPACEas the XML namespace provided for your installation,API_VERSIONas the API version number,TYPE(which can be “local” or “ldap”).NAMEandPASSWORDshould be obvious.Generate a POST request to
https://hostname/vCenter-CB/api/login?version=$API_VERSIONwith the raw POST-data set to the XML above. Remember to keep the session cookie you are sent after this request returns, as it represents your session to the server.Also, if you’re using LDAP logins, you may have to include an
LdapUserschild element below theUsers(as a sibling of theUserelement) to provide LDAP credentials. This is documented in the API Programming Guide from VMware.