0

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

5
  • Do they not give you an example? "URL parameter" sounds like you should be doing https://xx.xx.xx.xx/vCenter-CB/api/login?version=1.5.0 Commented Jul 21, 2011 at 6:53
  • They didn't give example in PHP but i have example in java, they created an object for PostMethod class and set the version using NameValuePair[] parameters = {new NameValuePair("version","1.5.0")}; post = new PostMethod(uri); post.setQueryString(parameters); I have tried https://xx.xx.xx.xx/vCenter-CB/api/login?version=1.5.0 also, it is still saying Bad Request. Commented Jul 21, 2011 at 7:42
  • That's useful. The query string is the part that comes after the ? in a url, not the body of the POST. So you're on the right track, but I don't know what else you're doing wrong as I have no idea what this API is and won't be reading its documentation. Commented Jul 21, 2011 at 8:42
  • I am still not able to say where I am going wrong.. Some one please help me Commented Jul 22, 2011 at 5:48
  • The reason you have no answers is that you have not provided enough information to help you, and even if you did by providing the API specification for the request you're trying to make, you're unlikely to get someone to read it and implement it for you for free. Commented Jul 22, 2011 at 6:09

1 Answer 1

1

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_NAMESPACE as the XML namespace provided for your installation, API_VERSION as the API version number, TYPE (which can be "local" or "ldap"). NAME and PASSWORD should be obvious.

<Request xmlns="$API_NAMESPACE/$API_VERSION">
    <Users>
        <User>
            <Type>$TYPE</Type>
            <Name>$NAME</Name>
            <Password>$PASSWORD</Password>
        </User>
    </Users>
</Request>

Generate a POST request to https://hostname/vCenter-CB/api/login?version=$API_VERSION with 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 LdapUsers child element below the Users (as a sibling of the User element) to provide LDAP credentials. This is documented in the API Programming Guide from VMware.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.