3 Replies Latest reply on Sep 3, 2014 12:58 AM by Lakshmi325

    REST CALL API in PHP

    pinky_clouditalia Lurker

      Hi, I've a problem with a call to the API for report generation in PHP.

       

      $curl = curl_init();

      curl_setopt($curl, CURLOPT_URL, "http://xxx.xxx.xxx.xxx/vCenter-CB/api/report?version=2.5");

      curl_setopt($curl, CURLOPT_PORT , 8080);

      curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: application/xml'));

      curl_setopt($curl, CURLOPT_HEADER, true);

      curl_setopt($curl, CURLOPT_POST, true);

      curl_setopt($curl, CURLOPT_VERBOSE, false);

      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

      curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");

      curl_setopt($curl, CURLOPT_TIMEOUT, 60);

      curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 60);

      curl_setopt($curl, CURLOPT_POSTFIELDS,     $chiamata);

      curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

      curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);

      curl_setopt($curl, CURLOPT_COOKIE, $cookie);

      $response = curl_exec($curl); 

       

      The body passed seems correct :

       

      <?xml version="1.0" encoding="UTF-8"?>

      <Request>

      <Reports>

      <Report>

      <MetaData>

      <Name>SampleReport</Name>

      <Description />

      <ReportType>COST_REPORT</ReportType>

      <OwnedByName />

      <ReportPeriod>

      <From>1</From>

      <To>9999999999999</To>

      </ReportPeriod>

      <Hierarchies>

      <Hierarchy id="132665">

      <Entities>

      <Entity id="132666" costModelId="931" />

      </Entities>

      </Hierarchy>

      </Hierarchies>

      <ComputingResources>

      <ComputingResource id="1" />

      <ComputingResource id="2" />

      <ComputingResource id="5" />

      <ComputingResource id="6" />

      <ComputingResource id="9" />

      <ComputingResource id="10" />

      </ComputingResources>

      </MetaData>

      <Configuration>

      <Computation>

      <Settings type="costVariance">

      <Property name="enabled" value="true" />

      <Property name="granularity" value="DAILY" />

      </Settings>

      </Computation>

      </Configuration>

      </Report>

      </Reports>

      </Request>

       

       

      Using a Rest client , it work with a corrent resonse.

      USing this method I receive a 200 OK for the call but the API give me this response :

       

      <?xml version="1.0" encoding="UTF-8"?>

      <Response xmlns="http://www.vmware.com/vcenter/chargeback/2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" status="failure">

        <Error majorErrorCode="500" minorErrorCode="0" message="No such method defined or API call missing required arguments." />

      </Response>

       

      any suggestion ?

      thanks

        • 1. Re: REST CALL API in PHP
          dprabhakaran Enthusiast
          VMware Employees

          pinky_clouditalia,

            Which version of Chargeback you use? Based on the version in request and response I see a version mismatch!

           

          Thanks

          Diwakar

          • 2. Re: REST CALL API in PHP
            pinky_clouditalia Lurker

            Manager and database version 2.6 . I've tried to call API with version 2.6 but don't work (not supported) . I've tried without specifing the the version (like the call thru Rest client) but always I receive the same 500 error in the API (200 in the API call).

            I've no problem with others calls (GET hierarchies or entities ...).

             

            thanks

             

             

            P.S. Changed the value for the <To> tag with conversion of the current datetime...

            • 3. Re: REST CALL API in PHP
              Lakshmi325 Novice
              VMware Employees

              Hi,

               

              One of the reason to get this error is, The request body sending in the API call could be empty. Please verify whether the request is setting properly before sending the API call. I tried with Rest client by passing request as empty and getting the same error.

               

              Thanks,

              Lakshmi