Integrating with php Sabre Soap API for hotels - php

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

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!

Related

Access web service via curl PHP or some thing similar

I have this type of API code and how can I send request to access this web service in php? can I use curl ? Please help me
Sandbox URL :
http://api.lankagate.gov.lk:8280/GetOnGoingVehicleNoDMT/1.0
Method POST
Parameter Name - vehicleCategory
Options - 1 , 4
Success Response Code: 200
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetOnGoingVehicleNoResponse
xmlns="http://schemas.conversesolutions.com/xsd/dmticta/v1">
<return>
<ResponseMessage xsi:nil="true" />
<ErrorCode xsi:nil="true" />
<OngoingVehicleNo>CAW-2186</OngoingVehicleNo>
</return>
</GetOnGoingVehicleNoResponse>
</soap:Body>
</soap:Envelope>
Sample
Call URL : http://api.lankagate.gov.lk:8280/Transliteration/1.0/
Message body :
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:v1="http://schemas.conversesolutions.com/xsd/dmticta/v1">
<soapenv:Header/>
<soapenv:Body>
<v1:GetOnGoingVehicleNo>
<v1:vehicleCategory>1</v1:vehicleCategory>
</v1:GetOnGoingVehicleNo>
</soapenv:Body>
</soapenv:Envelope>
Notes Set request header as
Authorization: Bearer Access Token
I have tried and this is my code
function get_exam_mode_of_study() {
$xml_data = '<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:v1="http://schemas.conversesolutions.com/xsd/dmticta/v1">
<soapenv:Header/>
<soapenv:Body>
<v1:GetOnGoingVehicleNo>
<v1:vehicleCategory>1</v1:vehicleCategory>
</v1:GetOnGoingVehicleNo>
</soapenv:Body>
</soapenv:Envelope>';
$URL = "http://api.lankagate.gov.lk:8280/GetOnGoingVehicleNoDMT/1.0";
$ch = curl_init($URL);
// curl_setopt($ch, CURLOPT_MUTE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
print_r($output);
exit;
curl_close($ch);
// }
}
and it gives following error
<ams:fault xmlns:ams="http://wso2.org/apimanager/security"><ams:code>900902</ams:code><ams:message>Missing Credentials</ams:message><ams:description>Required OAuth credentials not provided. Make sure your API invocation call has a header: "Authorization: Bearer ACCESS_TOKEN"</ams:description></ams:fault>
You need to add the Authorization header
CURLOPT_HTTPHEADER for curl_setopt() takes an array with each header as an element.
You can use below $header array.
$header = array();
$header[] = 'Content-length: 0';
$header[] = 'Content-type: application/json';
$header[] = 'Authorization: Bearer OAuthAccess_TokenThatIReceived';
curl_setopt($ch, CURLOPT_HTTPHEADER,$header);

Post SOAP XML Request

I was trying several examples from here, but nothing seems to work for me.
I need to send this envelope for the request:
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:v2="http://xmlns.oracle.com/oxp/service/v2">
<soapenv:Header />
<soapenv:Body>
<v2:runReport>
<v2:reportRequest>
<v2:attributeLocale>en-US</v2:attributeLocale>
<v2:attributeTemplate>Default</v2:attributeTemplate>
<v2:reportAbsolutePath>/Custom/Financials/Fac/XXIASA_FAC.xdo</v2:reportAbsolutePath>
<v2:dynamicDataSource xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
<v2:parameterNameValues xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
<v2:XDOPropertyList xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
</v2:reportRequest>
<v2:userID>user</v2:userID>
<v2:password>password</v2:password>
</v2:runReport>
</soapenv:Body>
</soapenv:Envelope>
This is my code:
$url = 'https://soapurl/v2/ReportService?WSDL';
$headers = array("Content-type: application/soap+xml; charset=\"utf-8\"", "Content-length: " . strlen($xml));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
print_r($response);
And this is the weird result I am getting back:
��R;o�0��+\ﱁTj�QZ�S_R���m�%sF�#��k�Q�l�����lwjT紅�$�H��Rñ���6OxW2gy�`�_aPƶ �|�\{��:Q��;�S���H���EG�<9���q$�v&gI�ҟ���l��6y��yB���?[��x���X5�a��6��5& ��<8�Q���e`�/F+������{���]������K�(2Q��T���X(�F*ϵ�k��eym����Ӊ��]�M�!y ��"m.�����0z�|�1���g�����}� ������C
Why I'm getting this?
If you used a network sniffer (I would recomend Wireshark), you would see that the data is compressed. This is usually employed server-side to reduce the bandwidth needed. Every single modern browser will decompress automatically, but curl on your application is not. If you saved that string on a file (response.bin, for example) and ran file response.bin, you will see the compressing algorithm employed (probably gzip or deflate).
To solve this, ask curl to decompress the response for you:
curl_setopt($ch,CURLOPT_ENCODING, '');

Soap Client in PHP

Hi Can anyone explain me in implementing below SOAP XML in PHP, I saw some questions they were handled using CURL but I want to use SoapClient library in PHP Can anyone help me.
I saw some people used below code in PHP get the simple SOAP , How can I implement the same way in my code
<?php
//Create the client object
$soapclient = new SoapClient('http://www.example.com:8080/test/services/test?wsdl');
//Use the functions of the client, the params of the function are in
//the associative array
$params = array(
'locationID' => '19087525238255',
'custFirstName' => 'Seure',
'custLastName' => 'Install',
'customerType' => 'RESI'
);
$response = $soapclient->octService($params);
var_dump($response);
?>
SOAP XML
<soapenv:Envelope xmlns:soapenv = "http://schemas.xmlsoap.org/soap/envelope/" xmlns:com = "http://test.com/">
<soapenv:Header/>
<soapenv:Body>
<com:OCTService>
<locationID>19087525238255</locationID>
<customer>
<custFirstName>JOHN</custFirstName>
<custLastName>ADAM</custLastName>
<customerType>RESI</customerType>
</customer>
<order>
<orderScheduleType>NoSchedule</orderScheduleType>
<orderScheduledate/>
<reasonCode>NT</reasonCode>
<salesRep>0001</salesRep>
</order>
<Equipments>
<equipment>
<serialNumber>*</serialNumber>
<type>N</type>
</equipment>
<equipment>
<serialNumber>*</serialNumber>
<type>NH</type>
</equipment>
<equipment>
<serialNumber>*</serialNumber>
<type>NH</type>
</equipment>
</Equipments>
<csgServiceCodes>
<CSGServiceCode>
<rateCode>SR002</rateCode>
<packageCode/>
</CSGServiceCode>
<CSGServiceCode>
<rateCode>BA</rateCode>
<packageCode/>
</CSGServiceCode>
</csgServiceCodes>
<voiceFeatures>
<nativeNumbersCount>0</nativeNumbersCount>
<portedNmbers>?</portedNmbers>
</voiceFeatures>
<HuntGroup>
<huntGroupType>?</huntGroupType>
</HuntGroup>
</com:OCTService>
</soapenv:Body>
</soapenv:Envelope>
I not able to achieve using CURL POST.
Here important thing is SOAPAction which you can use in the WSDL document
$headers = array(
"Accept-Encoding: gzip,deflate",
"Content-Type: text",
"Cache-Control: no-cache",
"Username: yourusername",
"Password: password",
"SOAPAction: urn:OCTService",
"Content-length: ".strlen($xml_post_string),
); //SOAPAction: your op URL
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($ch, CURLOPT_USERPWD, $soapUser.":".$soapPassword); // username and password - declared at the top of the doc
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);
echo $response;
curl_close($ch);
// converting
$response1 = str_replace("<soap:Body>","",$response);
$response2 = str_replace("</soap:Body>","",$response1);
// convertingc to XML
$parser = simplexml_load_string($response2);

SOAP XML call using PHP curl?

I have one SOAP WSDL api and i have a test api access.
My SOAP Url : https://development.avinode.com/avinode/AvinodeIntegrationWeb/ws/EmptyLegFlightDemand.ws?wsdl
i need to call and get the details from this url. i must send my username and password into this api call. so i tried to build the code. the code is given below.
<?php
$soapUrl='https://development.avinode.com:443/avinode/AvinodeIntegrationWeb/ws/EmptyLegDownload.ws?wsdl';
$xml_post_string='<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<S:Header>
<To xmlns="http://www.w3.org/2005/08/addressing">https://development.avinode.com/avinode/AvinodeIntegrationWeb/ws/EmptyLegDownload.ws</To>
<Action xmlns="http://www.w3.org/2005/08/addressing">http://www.avinode.com/integration/EmptyLegDownload#request</Action>
<ReplyTo xmlns="http://www.w3.org/2005/08/addressing">
<Address>http://www.w3.org/2005/08/addressing/anonymous</Address>
</ReplyTo>
<FaultTo xmlns="http://www.w3.org/2005/08/addressing">
<Address>http://www.w3.org/2005/08/addressing/anonymous</Address>
</FaultTo>
<MessageID xmlns="http://www.w3.org/2005/08/addressing">uuid:6a456287-923e-458e-9ccb-f900307f2b0f</MessageID>
<wsse:Security S:mustUnderstand="1">
<wsu:Timestamp xmlns:ns13="http://www.w3.org/2003/05/soap-envelope" xmlns:ns14="http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512" wsu:Id="_1">
<wsu:Created>2014-10-17T15:45:42Z</wsu:Created>
<wsu:Expires>2014-10-17T15:50:42Z</wsu:Expires>
</wsu:Timestamp>
<wsse:UsernameToken xmlns:ns13="http://www.w3.org/2003/05/soap-envelope" xmlns:ns14="http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512" wsu:Id="uuid_2da8da35-1c69-4f38-9899-ba6950c825f5">
<wsse:Username>MY_USERNAME</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">PASSWORD</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</S:Header>
<S:Body>
<ns3:request xmlns="http://www.avinode.com/core/CommonTypes" xmlns:ns2="http://www.avinode.com/services/EmptyLegDownload" xmlns:ns3="http://www.avinode.com/integration/EmptyLegDownload">
<ns2:product>
<name>osiz</name>
<version>1.0</version>
</ns2:product>
<ns2:domain>http://flightcomparision.osiztechnologies.com</ns2:domain>
<ns2:locale>en_US</ns2:locale>
<ns2:currency>USD</ns2:currency>
<ns2:region>AMERICA</ns2:region>
<ns2:after>2014-11-01T00:00:00Z</ns2:after>
<ns2:before>2014-12-01T00:00:00Z</ns2:before>
<ns2:pax>1</ns2:pax>
<ns2:excludeBrokers>false</ns2:excludeBrokers>
<ns2:requireTailNumber>false</ns2:requireTailNumber>
</ns3:request>
</S:Body>
</S:Envelope>';
$headers = array(
"Content-Type: text/xml;charset=UTF-8",
"Accept: gzip,deflate",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: \"\"",
"Authorization: Basic $auth",
"Content-length: ".strlen($xml_post_string),
);
// PHP cURL for https connection with auth
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $soapUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_TIMEOUT, 500);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 500);
curl_setopt($ch, CURLOPT_MAXREDIRS, 12);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$ss = curl_getinfo($ch);
//print_r($ss);
// exit;
$response = curl_exec($ch);
print_r($response);
exit;
curl_close($ch);
?>
I got only Empty response only please give me any idea highly appreciated.
I would start by adding:
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
That will allow you to see the response http code of the server.
Usually when I work on SOAP / REST services I make sure to have Fiddler running in the background, that makes debugging a lot easier.
You can find how to use Fiddler with cURL here: Configure PHP cURL

How to call soap api using php?

I have following soap response. How can i call soap using php.Any Idea. Thanks in Advance.
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/07/secext">
<wsse:UsernameToken>
<wsse:Username>XXXXXXXXXXXX</wsse:Username>
<wsse:Password>XXXXXXXXXXXXXXXXX</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soap:Header>
<soapenv:Body>
<cus1:GetCustomerDetailsRequest xmlns:cus1="XXXXXXXXXXXXXXXXXXXXXXX" xmlns:com="XXXXXXXXXXXXXXXXXXXXXXXX" xmlns:cus="XXXXXXXXXXXXXXXXX">
<cus:GetCustomerDetails>
<AccountMSISDN>1234567890</AccountMSISDN>
</cus:GetCustomerDetails>
</cus1:GetCustomerDetailsRequest>
</soapenv:Body>
</soapenv:Envelope>
You should be able to have a play around with the fields, parameters and methods you need by using a free online soap tool like this:
http://www.soapclient.com/soaptest.html
Also, you should have a look at this answer: SOAP request in PHP with CURL
$soapUrl = "http://www.example.com/masterdata/masterdata.asmx?wsdl";
$soapUser = "username"; // username
$soapPassword = "password"; // password
// xml post structure
$xml_post_string = 'soap string'; // data from the form, e.g. some ID number
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: http://tempuri.org/GetMasterData",
"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_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $soapUser.":".$soapPassword); // username and password - declared at the top of the doc
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);
// a new dom object
$dom = new domDocument('1.0', 'utf-8');
// load the html into the object
$dom->loadXml($response);
$array = json_decode($dom->textContent,TRUE);
print_r($array);

Categories