1

I am trying to connect to the Mind Body Online API (their forum is down currently, so I came here). Below is the code I am using. I am receiving this:

SERVER ERROR 405 - HTTP verb used to access this page is not allowed. The page you are looking for cannot be displayed because an invalid method (HTTP verb) was used to attempt to access.

code:

//Data, connection, auth
    $soapUrl = "http://clients.mindbodyonline.com/api/0_5/ClassService.asmx?WSDL";
    // xml post structure

    $xml_post_string = '<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://clients.mindbodyonline.com/api/0_5/GetClasses">
            <soapenv:Header/>
            <soapenv:Body>
               <GetClasses>
                  <Request>
                     <SourceCredentials>
                        <SourceName>{username}</SourceName>
                        <Password>{password}</Password>
                        <SiteIDs>
                           <int>{siteid}</int>
                        </SiteIDs>
                     </SourceCredentials>
                     <XMLDetail>Basic</XMLDetail>
                     <PageSize>10</PageSize>
                     <CurrentPageIndex>0</CurrentPageIndex>
                     <SchedulingWindow>true</SchedulingWindow>
                  </Request>
               </GetClasses>
            </soapenv:Body>
         </soapenv:Envelope>';

       $headers = array(
                    "Content-type: text/xml;charset=\"utf-8\"",
                    "Accept: text/xml",
                    "Cache-Control: no-cache",
                    "Pragma: no-cache",
                    "SOAPAction: http://clients.mindbodyonline.com/api/0_5/GetClasses", 
                    "Content-length: ".strlen($xml_post_string),
                ); //SOAPAction: your op URL

        $url = $soapUrl;

        // PHP cURL  for https connection with auth
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

        // converting
        $response = curl_exec($ch); 
        curl_close($ch);

        var_dump($response);

        // converting
        //$response1 = str_replace("<soap:Body>","",$response);
        //$response2 = str_replace("</soap:Body>","",$response1);

        // convertingc to XML
        //$parser = simplexml_load_string($response2);
        // user $parser to get your data out of XML response and to display it. 

Any help would be great and if anyone has any experience working with their API, my first time ;)

Here is the post on stack I am going off of: SOAP request in PHP

EDIT:

var dump of response:

string(733) "soap:ServerSystem.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object. at mb.API._0_5.ClassService.GetClasses(GetClassesRequest Request) in e:\Builds\1\mb\mb-clients_stageclients\Sources\mb-clients\API\0_5\ClassService.asmx.cs:line 226 --- End of inner exception stack trace ---"
Community
  • 1
  • 1
klye_g
  • 1,242
  • 6
  • 31
  • 54
  • `their forum is down currently,` Maybe then their WSDL URL is also messed up? I have you tried accessing the WSDL Url directly? Also are the forums back up? If so try the script again. – Sammaye Jun 30 '12 at 16:01
  • see edit in question, var dump of response – klye_g Jun 30 '12 at 16:16

1 Answers1

0

This is working for me

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.mindbodyonline.com/0_5/ClientService.asmx",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n  <soap:Body>\r\n    <GetClients xmlns=\"http://clients.mindbodyonline.com/api/0_5\">\r\n      <Request>\r\n        <SourceCredentials>\r\n                        <SourceName>xxxxxx</SourceName>\r\n                        <Password>xxxxx=</Password>\r\n                        <SiteIDs>\r\n                           <int>-99</int>\r\n                        </SiteIDs>\r\n                     </SourceCredentials>\r\n                     <ClientIDs>\r\n          <string></string>\r\n        </ClientIDs>\r\n                             <XMLDetail>Full</XMLDetail>\r\n\r\n        <SearchText>ccc@ccc.com</SearchText>\r\n      </Request>\r\n    </GetClients>\r\n  </soap:Body>\r\n</soap:Envelope>",
  CURLOPT_HTTPHEADER => array(
    "cache-control: no-cache",
    "content-type: text/xml",
    "soapaction: http://clients.mindbodyonline.com/api/0_5/GetClients"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
Keshav Kalra
  • 305
  • 5
  • 8