saad
saad

Reputation: 1364

Integrating with php Sabre Soap API for hotels

Following the Sabre authentication process from here

https://developer.sabre.com/docs/read/soap_basics/Authentication

Want to get sabre SOAP API results with php, but there are problems getting the response, using curl as seen in following code

$input_xml = '
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:eb="http://www.ebxml.org/namespaces/messageHeader" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
    <SOAP-ENV:Header>
        <eb:MessageHeader SOAP-ENV:mustUnderstand="1" eb:version="1.0">
            <eb:ConversationId/>
            <eb:From>
                <eb:PartyId type="urn:x12.org:IO5:01">999999</eb:PartyId>
            </eb:From>
            <eb:To>
                <eb:PartyId type="urn:x12.org:IO5:01">123123</eb:PartyId>
            </eb:To>
            <eb:CPAId>IPCC</eb:CPAId>
            <eb:Service eb:type="OTA">SessionCreateRQ</eb:Service>
            <eb:Action>SessionCreateRQ</eb:Action>
            <eb:MessageData>
                <eb:MessageId>1000</eb:MessageId>
                <eb:Timestamp>2001-02-15T11:15:12Z</eb:Timestamp>
                <eb:TimeToLive>2001-02-15T11:15:12Z</eb:TimeToLive>
            </eb:MessageData>
        </eb:MessageHeader>
        <wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext" xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/12/utility">
            <wsse:UsernameToken> 
                <wsse:Username>USERNAME</wsse:Username>
                <wsse:Password>PASSWORD</wsse:Password>
                <Organization>IPCC</Organization>
                <Domain>DEFAULT</Domain> 
            </wsse:UsernameToken>
        </wsse:Security>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
        <eb:Manifest SOAP-ENV:mustUnderstand="1" eb:version="1.0">
            <eb:Reference xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="cid:rootelement" xlink:type="simple"/>
        </eb:Manifest>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>';
    $url = $envUrl;

        //setting the curl parameters.
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
// Following line is compulsary to add as it is:
        curl_setopt($ch, CURLOPT_POSTFIELDS,
                    "xmlRequest=" . $input_xml);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
        $data = curl_exec($ch);
        curl_close($ch);

        //convert the XML result into array
        $array_data = json_decode(json_encode(simplexml_load_string($data)), true);

        print_r('<pre>');
        print_r($array_data);
        print_r('</pre>');

The $array_data returns nothing + also tried to create session before

https://developer.sabre.com/docs/read/soap_apis/session_management/create_session

but the response is same. I know there there is some good way to communicate with sabre in php, please help me find it

Upvotes: 0

Views: 998

Answers (1)

shahzam
shahzam

Reputation: 341

This question is a few months old, but maybe my answer might still be useful nonetheless.

I've managed to use PHP and CURL successfully to communicate with Sabre's SOAP API. Looking at your code and comparing with my own, I have a few suggestions:

1) Try passing some HTTP header information with your SOAP call as follows (I remember this as being somewhat important):

$action = 'SessionCreateRQ'; // Set this to whatever Sabre API action you are calling

$soapXML = $input_xml; // Your SOAP XML

$headers = array( 
   'Content-Type: text/xml; charset="utf-8"', 
   'Content-Length: ' . strlen($soapXML), 
   'Accept: text/xml', 
   'Keep-Alive: 300', 
   'Connection: keep-alive', 
   'Cache-Control: no-cache', 
   'Pragma: no-cache', 
   'SOAPAction: "' . $action . '"'
); 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $soapXML);

2) After your call to curl_exec, check for any errors as follows which should help with debugging:

$data = curl_exec($ch);
if(curl_error($ch)) {
    echo "Curl error: " . curl_error($ch);
} else {
    echo $data;
    ...
}

3) Many Sabre SOAP API calls require that you create a session first. So that often requires making a SOAP request with SessionCreateRQ, after which you can make another SOAP call for your desired action, followed by another SOAP request to SessionCloseRQ to close the session. Each SOAP request needs the full header and payload set correctly, which can be sort of a pain, but that's the required flow.

I hope that helps!

Upvotes: 1

Related Questions