php curl http 405 error mind body online api

Posted by K_G on Stack Overflow See other posts from Stack Overflow or by K_G
Published on 2012-06-30T15:11:07Z Indexed on 2012/06/30 15:15 UTC
Read the original article Hit count: 242

Filed under:
|
|
|
|

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";
    // 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">
                        <soapenv:Header/>
                            <soapenv:Body>
                                <GetClasses>
                                    <Request>
                                        <SourceCredentials>
                                                <SourceName>username</SourceName>
                                                <Password>password</Password>
                                            <SiteIDs>
                                                <int>site id</int>
                                            </SiteIDs>
                                        </SourceCredentials>
                                            <UserCredentials>
                                                <Username>username</Username>
                                                <Password>password</Password>
                                                <SiteIDs>
                                                    <int></int>
                                                </SiteIDs>
                                            </UserCredentials>
                                        <Fields>
                                            <string>Classes.Resource</string>
                                        </Fields>
                                    <XMLDetail>Basic</XMLDetail>
                                    <PageSize>10</PageSize>
                                    <CurrentPageIndex>0</CurrentPageIndex>
                                </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", 
                    "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

© Stack Overflow or respective owner

Related posts about php

Related posts about http