PHP XML Request Travelport API - php

I'm trying to get a response from Travelports uAPI via XML/SOAP but i'm not just getting anything useful. print_r and var_dump and an echo all just show Resource id #2 which IS something but can't get any further.
I've tried their API Test Tool to send XML requests and it works fine but just can't get it to work in PHP. I've parsed XML before but never send requests.
Code:
<?php
$CREDENTIALS = '******************';
$message = '
<?xml version="1.0" encoding="utf-16"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<s:Body>
<air:AvailabilitySearchReq TraceId="P107788" AuthorizedBy="User" TargetBranch="P107788" xmlns:air="http://www.travelport.com/schema/air_v23_0" xmlns:com="http://www.travelport.com/schema/common_v20_0">
<com:BillingPointOfSaleInfo OriginApplication="UAPI" />
<air:SearchAirLeg>
<air:SearchOrigin>
<com:Airport Code="SYD" />
</air:SearchOrigin>
<air:SearchDestination>
<com:Airport Code="MEL" />
</air:SearchDestination>
<air:SearchDepTime PreferredTime="2013-12-30" />
</air:SearchAirLeg>
<air:SearchAirLeg>
<air:SearchOrigin>
<com:Airport Code="MEL" />
</air:SearchOrigin>
<air:SearchDestination>
<com:Airport Code="SYD" />
</air:SearchDestination>
<air:SearchDepTime PreferredTime="2014-01-02" />
</air:SearchAirLeg>
<air:AirSearchModifiers>
<air:PreferredProviders>
<com:Provider Code="1P" />
</air:PreferredProviders>
<air:PreferredCarriers>
<com:Carrier Code="QF" />
</air:PreferredCarriers>
</air:AirSearchModifiers>
<com:SearchPassenger Code="ADT" />
<com:SearchPassenger Code="ADT" />
</air:AvailabilitySearchReq>
</s:Body>
</s:Envelope>
';
$auth = $CREDENTIALS; //should base_64_encode() this!
$soap_do = curl_init("https://americas-uapi.copy-webservices.travelport.com/B2BGateway/connect/uAPI/Service");
$header = 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($message),
);
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 60);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $message);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, $header);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true);
curl_exec($soap_do);
print_r($soap_do); echo '<br>';
var_dump($soap_do);
echo '<br>'.$soap_do;
?>
Any help just to get me started would be great. :)

I am a Partner Technical Specialist at Travelport, and I understand your frustration. Our previous usage and description of endpoints has been confusing. There are updated PHP samples if you log into our developer portal;
https://developer.travelport.com/app/developer-network/resource-centre-uapi
The easiest is to 'Deselect All', then select specifically for 'Sample Code'.
Give those a try!

Just change
$soap_do = curl_init("https://americas-uapi.copy-webservices.travelport.com/B2BGateway/connect/uAPI/Service");
to
$soap_do = curl_init("https://americas-uapi.copy-webservices.travelport.com/B2BGateway/connect/uAPI/AirService");

Related

PHP Curl Fucntion not working in ajax call?

I am sending the Xml request and getting the response using the CURL request function. If i send the static value i got the response But if i send the dynamic values using PHP file the response not able to get it. May i know where i mistake
Included the 2 codes
<?xml version="1.0" encoding="UTF-8"?>
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP:Body>
<serve xmlns="http://schemas.cordys.com/gateway/Provider">
<SessionDoc xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://schemas.cordys.com/gateway/Provider">
<Session>
<SessionData xmlns="XXXX">
<Index>1</Index>
<InitTime>Thu, 05 Oct 17 15:55:44 +0530</InitTime>
<UserName>XXXXX</UserName>
<Password>XXXXX</Password>
<OrderNo>NA</OrderNo>
<QuoteNo>NA</QuoteNo>
<Route>INT</Route>
<Contract>XXX</Contract>
<Channel>XXX</Channel>
<TransactionType>Quote</TransactionType>
<TransactionStatus>Fresh</TransactionStatus>
<ID>XXXXXX</ID>
<UserAgentID>XXXX</UserAgentID>
<Source>XXXX</Source>
<IsCCUser>N</IsCCUser>
</SessionData>
<tns:Vehicle xmlns:tns="XXXXX">
<tns:TypeOfBusiness>TR</tns:TypeOfBusiness>
<tns:AccessoryInsured>N</tns:AccessoryInsured>
<tns:AccessoryValue>0</tns:AccessoryValue>
<tns:AntiTheftDevice>N</tns:AntiTheftDevice>
<tns:BiFuelKit>
<tns:IsBiFuelKit>N</tns:IsBiFuelKit>
<tns:BiFuelKitValue>0</tns:BiFuelKitValue>
<tns:ExternallyFitted>N</tns:ExternallyFitted>
</tns:BiFuelKit>
<tns:DateOfRegistration></tns:DateOfRegistration>
<tns:RiskType>FTW</tns:RiskType>
<tns:Make>HONDA MOTORS</tns:Make>
<tns:Model>ACTIVA</tns:Model>
<tns:FuelType>P</tns:FuelType>
<tns:Variant>3G</tns:Variant>
<tns:IDV>20202</tns:IDV>
<tns:EngineNo></tns:EngineNo>
<tns:ChasisNo></tns:ChasisNo>
<tns:DriveExperiance />
<tns:NoOfDrivers />
<tns:ParkingType />
<tns:AnnualMileage />
<tns:YoungestDriverAge />
<tns:PaidDriver />
<tns:VehicleAge>4</tns:VehicleAge>
<tns:CC>109</tns:CC>
<tns:PlaceOfRegistration>Mumbai Navi Mumbai</tns:PlaceOfRegistration>
<tns:SeatingCapacity>2</tns:SeatingCapacity>
<tns:VehicleExtraTag01 />
<tns:RegistrationNo></tns:RegistrationNo>
<tns:ExShowroomPrice>51800</tns:ExShowroomPrice>
<tns:DateOfManufacture>2014</tns:DateOfManufacture>
</tns:Vehicle>
<tns:Quote xmlns:tns="XXXXXX">
<PolicyTenure>1</PolicyTenure>
<tns:ExistingPolicy>
<tns:Claims>0</tns:Claims>
<tns:PolicyType>Comprehensive</tns:PolicyType>
<tns:EndDate></tns:EndDate>
<tns:NCB>0</tns:NCB>
<tns:PolicyNo></tns:PolicyNo>
<tns:InsuranceCompany></tns:InsuranceCompany>
</tns:ExistingPolicy>
<tns:PolicyStartDate>2017-10-06T00:00:00.000</tns:PolicyStartDate>
<tns:Deductible>0</tns:Deductible>
<tns:PAFamilySI>100000</tns:PAFamilySI>
<tns:AgentNumber>2C000002</tns:AgentNumber>
<tns:DealerId>619</tns:DealerId>
<tns:Premium>
<tns:Discount />
</tns:Premium>
<tns:SelectedCovers>
<tns:CarDamageSelected>true</tns:CarDamageSelected>
<tns:TPLiabilitySelected>true</tns:TPLiabilitySelected>
<tns:PADriverSelected>true</tns:PADriverSelected>
<tns:ZeroDepriciationSelected>false</tns:ZeroDepriciationSelected>
<tns:RoadsideAssistanceSelected>false</tns:RoadsideAssistanceSelected>
<tns:InvoicePriceSelected>false</tns:InvoicePriceSelected>
<tns:InvoicePriceCoverAmount />
<tns:PAFamilyPremiumSelected>false</tns:PAFamilyPremiumSelected>
<tns:HospitalCashSelected>false</tns:HospitalCashSelected>
<tns:MedicalExpensesSelected>false</tns:MedicalExpensesSelected>
<tns:AmbulanceChargesSelected>false</tns:AmbulanceChargesSelected>
<tns:CosumableCoverSelected>false</tns:CosumableCoverSelected>
<tns:HydrostaticLockSelected>false</tns:HydrostaticLockSelected>
<tns:KeyReplacementSelected>false</tns:KeyReplacementSelected>
<tns:NoClaimBonusSameSlabSelected>false</tns:NoClaimBonusSameSlabSelected>
<tns:EngineGearBoxProtectionSelected>false</tns:EngineGearBoxProtectionSelected>
</tns:SelectedCovers>
<tns:PolicyEndDate>2018-10-05T23:59:59.000</tns:PolicyEndDate>
</tns:Quote>
<tns:Client xmlns:tns="XXX">
<tns:ClientType>Individual</tns:ClientType>
<tns:CltDOB></tns:CltDOB>
<tns:FinancierDetails>
<tns:IsFinanced>0</tns:IsFinanced>
<tns:InstitutionName></tns:InstitutionName>
<tns:InstitutionCity></tns:InstitutionCity>
</tns:FinancierDetails>
<tns:GivName>BharatiTwo1507199144</tns:GivName>
<tns:ClientExtraTag01>MAHARASHTRA</tns:ClientExtraTag01>
<tns:CityOfResidence>Mumbai Navi Mumbai</tns:CityOfResidence>
<tns:EmailID>dfgkgj#KJhj.com</tns:EmailID>
<tns:MobileNo>9865325896</tns:MobileNo>
<tns:LandLineNo></tns:LandLineNo>
<tns:SurName></tns:SurName>
<tns:CltSex></tns:CltSex>
<tns:Marryd></tns:Marryd>
<tns:Occupation></tns:Occupation>
<tns:CltAddr01></tns:CltAddr01>
<tns:CltAddr02></tns:CltAddr02>
<tns:CltAddr03></tns:CltAddr03>
<tns:City></tns:City>
<tns:State></tns:State>
<tns:PinCode></tns:PinCode>
<tns:Nominee>
<tns:Name></tns:Name>
<tns:Age></tns:Age>
<tns:Relationship></tns:Relationship>
<tns:Appointee></tns:Appointee>
<tns:AppointeeRelation></tns:AppointeeRelation>
</tns:Nominee>
<tns:RegistrationZone>B</tns:RegistrationZone>
<GstinNo>GSTinNO</GstinNo>
</tns:Client>
<Payment>
<PaymentMode />
<PaymentType />
<TxnReferenceNo />
<TxnAmount />
<TxnDate />
<BankCode />
<InstrumentAmount />
</Payment>
</Session>
</SessionDoc>
</serve>
</SOAP:Body>
</SOAP:Envelope>';
$headers = array(
"Content-type: application/xml",
"Content-length: " . strlen($xml),
"Connection: close",
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
echo "<pre>";
echo $data = curl_exec($ch); exit;
this is code for Dynamic generation using PHP Values which we passed
<?xml version="1.0" encoding="UTF-8"?>
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP:Body>
<serve xmlns="http://schemas.cordys.com/gateway/Provider">
<SessionDoc xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://schemas.cordys.com/gateway/Provider">
<Session>
<SessionData xmlns="XXX">
<Index>'.$stage.'</Index>
<InitTime>'.$current_date.'</InitTime>
<UserName>XXXXX</UserName>
<Password>XXXX</Password>
<OrderNo>'.$order_no.'</OrderNo>
<QuoteNo>'.$quote_no.'</QuoteNo>
<Route>INT</Route>
<Contract>MTR</Contract>
<Channel>XXXX</Channel>
<TransactionType>Quote</TransactionType>
<TransactionStatus>Fresh</TransactionStatus>
<ID>XXXXX</ID>
<UserAgentID>2C000002</UserAgentID>
<Source>2C000002</Source>
<IsCCUser>N</IsCCUser>
</SessionData>
<tns:Vehicle xmlns:tns="XXX">
<tns:TypeOfBusiness>'.$bis_type.'</tns:TypeOfBusiness>
<tns:AccessoryInsured>'.$access_ins.'</tns:AccessoryInsured>
<tns:AccessoryValue>'.$access_val.'</tns:AccessoryValue>
<tns:AntiTheftDevice>'.$anti_thfdev.'</tns:AntiTheftDevice>
<tns:BiFuelKit>
<tns:IsBiFuelKit>'.$fuel_kit.'</tns:IsBiFuelKit>
<tns:BiFuelKitValue>'.$fuel_kit_val.'</tns:BiFuelKitValue>
<tns:ExternallyFitted>'.$ext_fit.'</tns:ExternallyFitted>
</tns:BiFuelKit>
<tns:DateOfRegistration>'.$veh_reg_date.'</tns:DateOfRegistration>
<tns:RiskType>'.$risktype.'</tns:RiskType>
<tns:Make>'.$make.'</tns:Make>
<tns:Model>'.$model.'</tns:Model>
<tns:FuelType>'.$fuel_type.'</tns:FuelType>
<tns:Variant>'.$variant.'</tns:Variant>
<tns:IDV>'.$idv.'</tns:IDV>
<tns:EngineNo>'.$engine_no.'</tns:EngineNo>
<tns:ChasisNo>'.$chasis_no.'</tns:ChasisNo>
<tns:DriveExperiance />
<tns:NoOfDrivers />
<tns:ParkingType />
<tns:AnnualMileage />
<tns:YoungestDriverAge />
<tns:PaidDriver />
<tns:VehicleAge>'.$veh_age.'</tns:VehicleAge>
<tns:CC>'.$cc.'</tns:CC>
<tns:PlaceOfRegistration>'.$place_reg.'</tns:PlaceOfRegistration>
<tns:SeatingCapacity>'.$seating.'</tns:SeatingCapacity>
<tns:VehicleExtraTag01 />
<tns:RegistrationNo>'.$veh_number.'</tns:RegistrationNo>
<tns:ExShowroomPrice>'.$x_shw_prc.'</tns:ExShowroomPrice>
<tns:DateOfManufacture>'.$mnf_year.'</tns:DateOfManufacture>
</tns:Vehicle>
<tns:Quote xmlns:tns="XXXX">
<PolicyTenure>'.$policy_tenure.'</PolicyTenure>
<tns:ExistingPolicy>
<tns:Claims>0</tns:Claims>
<tns:PolicyType>Comprehensive</tns:PolicyType>
<tns:EndDate>'.$ext_policy_enddate.'</tns:EndDate>
<tns:NCB>'.$ncb_val.'</tns:NCB>
<tns:PolicyNo>'.$policy_no.'</tns:PolicyNo>
<tns:InsuranceCompany>'.$ins_cmp.'</tns:InsuranceCompany>
</tns:ExistingPolicy>
<tns:PolicyStartDate>'.$policy_stdate.'</tns:PolicyStartDate>
<tns:Deductible>'.$deductable.'</tns:Deductible>
<tns:PAFamilySI>100000</tns:PAFamilySI>
<tns:AgentNumber>2C000002</tns:AgentNumber>
<tns:DealerId>619</tns:DealerId>
<tns:Premium>
<tns:Discount />
</tns:Premium>
<tns:SelectedCovers>
<tns:CarDamageSelected>true</tns:CarDamageSelected>
<tns:TPLiabilitySelected>true</tns:TPLiabilitySelected>
<tns:PADriverSelected>true</tns:PADriverSelected>
<tns:ZeroDepriciationSelected>'.$addons_list['DEPC'].'</tns:ZeroDepriciationSelected>
<tns:RoadsideAssistanceSelected>'.$addons_list['RSAC'].'</tns:RoadsideAssistanceSelected>
<tns:InvoicePriceSelected>'.$addons_list['INPC'].'</tns:InvoicePriceSelected>
<tns:InvoicePriceCoverAmount />
<tns:PAFamilyPremiumSelected>'.$addons_list['PAFamily'].'</tns:PAFamilyPremiumSelected>
<tns:HospitalCashSelected>'.$addons_list['HOSP'].'</tns:HospitalCashSelected>
<tns:MedicalExpensesSelected>'.$addons_list['MEDI'].'</tns:MedicalExpensesSelected>
<tns:AmbulanceChargesSelected>'.$addons_list['AMBC'].'</tns:AmbulanceChargesSelected>
<tns:CosumableCoverSelected>'.$addons_list['CONC'].'</tns:CosumableCoverSelected>
<tns:HydrostaticLockSelected>'.$addons_list['HYLC'].'</tns:HydrostaticLockSelected>
<tns:KeyReplacementSelected>'.$addons_list['KEYC'].'</tns:KeyReplacementSelected>
<tns:NoClaimBonusSameSlabSelected>'.$addons_list['NCBS'].'</tns:NoClaimBonusSameSlabSelected>
<tns:EngineGearBoxProtectionSelected>'.$addons_list['EGBP'].'</tns:EngineGearBoxProtectionSelected>
</tns:SelectedCovers>
<tns:PolicyEndDate>'.$policy_endate.'</tns:PolicyEndDate>
</tns:Quote>
<tns:Client xmlns:tns="XXXX">
<tns:ClientType>Individual</tns:ClientType>
<tns:CltDOB>'.$clnt_dob.'</tns:CltDOB>
<tns:FinancierDetails>
<tns:IsFinanced>'.$is_fin.'</tns:IsFinanced>
<tns:InstitutionName>'.$fin_name.'</tns:InstitutionName>
<tns:InstitutionCity>'.$fin_city.'</tns:InstitutionCity>
</tns:FinancierDetails>
<tns:GivName>'.$first_name.'</tns:GivName>
<tns:ClientExtraTag01>'.$reg_state.'</tns:ClientExtraTag01>
<tns:CityOfResidence>'.$rto.'</tns:CityOfResidence>
<tns:EmailID>'.$email_id.'</tns:EmailID>
<tns:MobileNo>'.$mobile_no.'</tns:MobileNo>
<tns:LandLineNo>'.$emg_cnt_no.'</tns:LandLineNo>
<tns:SurName>'.$last_name.'</tns:SurName>
<tns:CltSex>'.$gender.'</tns:CltSex>
<tns:Marryd>'.$martial_status.'</tns:Marryd>
<tns:Occupation>'.$occup.'</tns:Occupation>
<tns:CltAddr01>'.$addr1.'</tns:CltAddr01>
<tns:CltAddr02>'.$addr2.'</tns:CltAddr02>
<tns:CltAddr03>'.$landmark.'</tns:CltAddr03>
<tns:City>'.$city.'</tns:City>
<tns:State>'.$state.'</tns:State>
<tns:PinCode>'.$pincode.'</tns:PinCode>
<tns:Nominee>
<tns:Name>'.$nom_name.'</tns:Name>
<tns:Age>'.$nom_age.'</tns:Age>
<tns:Relationship>'.$nom_rel.'</tns:Relationship>
<tns:Appointee>'.$nom_apnt.'</tns:Appointee>
<tns:AppointeeRelation>'.$nom_apnt_rel.'</tns:AppointeeRelation>
</tns:Nominee>
<tns:RegistrationZone>'.$reg_zone.'</tns:RegistrationZone>
<GstinNo></GstinNo>
</tns:Client>
<Payment>
<PaymentMode />
<PaymentType />
<TxnReferenceNo />
<TxnAmount />
<TxnDate />
<BankCode />
<InstrumentAmount />
</Payment>
</Session>
</SessionDoc>
</serve>
</SOAP:Body>
</SOAP:Envelope>';
$headers = array(
"Content-type: application/xml",
"Content-length: " . strlen($xml),
"Connection: close",
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$data = curl_exec($ch);
Where i did wrong here. Please clear me

Posting a SOAP request with php

I'm at a slight loss, havent touched a soap script in forever and looking around stackoverflow and google just confuses the matter more. PHP.net examples seem outdated as well.
The SOAP Request is supposed to POST to a non-WSDL url.
https://some.soapurl.com/provided
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:cam="http://kamp.gw.com/kamp">
<soapenv:Header/>
<soapenv:Body>
<cam:setRolesUpdatedRequest>
<cam:orgCode>username</cam:orgCode>
<cam:password>password</cam:password>
<cam:emails>
<cam:email>abc#dom.com</cam:email>
<cam:email>def#dom.com</cam:email>
<cam:email>ghi#dom.com</cam:email>
</cam:emails>
<cam:updateAllUsers>false</cam:updateAllUsers>
</cam:setRolesUpdatedRequest>
</soapenv:Body>
</soapenv:Envelope>
Just running this snippet returns a 200 OK header, which is good.
try {
$client = new SoapClient("https://abc.kamp.group.com/axis/services/KampService/setRolesUpdated");
}
catch(Exception $e)
{
$e->getMessage();
}
The Response i'm looking to get is supposed to look like
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns1:returnStatus xmlns:ns1="http://kamp.gw.com/kamp">
<ns1:type>S</ns1:type>
<ns1:desc>Successful</ns1:desc>
</ns1:returnStatus>
</soapenv:Body>
</soapenv:Envelope>
EDIT:
I attempted a curl version to post the xml string directly.
$post_string = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cam="http://kamp.gw.com/kamp">
<soapenv:Header/>
<soapenv:Body>
<cam:setRolesUpdatedRequest>
<cam:orgCode>username</cam:orgCode>
<cam:password>password</cam:password>
<cam:emails>
<cam:email>abc#dom.com</cam:email>
<cam:email>def#dom.com</cam:email>
<cam:email>ghi#dom.com</cam:email>
</cam:emails>
<cam:updateAllUsers>false</cam:updateAllUsers>
</cam:setRolesUpdatedRequest>
</soapenv:Body>
</soapenv:Envelope>';
$user = "username";
$password = "password";
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: \"run\"",
"Content-length: ".strlen($xml),
);
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, "https://abc.kamp.group.com/axis/services/KampService/setRolesUpdated" );
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 100000);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 100000);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, $headers); //array('Content-Type: text/xml; charset=utf-8', 'Content-Length: '.strlen($post_string) )
curl_setopt($soap_do, CURLOPT_USERPWD, $user . ":" . $password);
$result = curl_exec($soap_do);
$err = curl_error($soap_do);
var_dump($result);
echo "<br /><br />";
var_dump($err);
But unfortunately the result is
bool(false)
string(74) "Failed connect to abc.kamp.group.com:443; Connection timed out"
And i'm not certain if that's my fault or the web service's fault. Even though i get connection timed out, the header returned is still 200 Ok.
First check that the SOAP service url and access credentials are working. Use SoapUI or a similar tool to make a request independent of your PHP SoapClient code.
Also check if there are any IP address restrictions in place when making calls and, if so, create / ask for an exception for the IP address you are making requests from.
If everything checks, use php.net SoapClient examples to make simple calls and build your script logic.
<?php
$client = new SoapClient('http://soap.amazon.com/schemas3/AmazonWebServices.wsdl');
var_dump($client->__getFunctions());
?>
Forgot i was behind a proxy, once i pointed curl to the proxy server everything worked out just fine.

How to issue a SOAP request in PHP

I am trying to issue a SOAP request in PHP. I have my service URL, and when I check it in SOAP UI, I can see the following
<application xmlns="http://somenamespace.com">
<doc xml:lang="en" title="https://someurl.com"/>
<resources base="https://someurl.com">
<resource path="sdk/user/session/logon/" id="Logon">
<doc xml:lang="en" title="Logon"/>
<param name="ApiKey" type="xs:string" required="false" default="" style="query" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
<param name="ApiSecret" type="xs:string" required="false" default="" style="query" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
<method name="POST" id="Logon">
<doc xml:lang="en" title="Logon"/>
<request>
<param name="method" type="xs:string" required="true" default="" style="query" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
<representation mediaType="application/json"/>
<representation mediaType="application/xml"/>
<representation mediaType="text/xml"/>
<representation mediaType="application/x-www-form-urlencoded"/>
</request>
<response status="404 500">
<representation mediaType="text/html; charset=utf-8" element="html"/>
</response>
<response status="">
<representation mediaType="application/json"/>
<representation mediaType="application/xml"/>
<representation mediaType="text/xml"/>
<representation mediaType="application/x-www-form-urlencoded"/>
</response>
<response status="500">
<representation mediaType="application/vnd.marg.bcsocial.result-v1.9+json; charset=utf-8" element="log:Fault" xmlns:log="https://someurl.com/sdk/user/session/logon"/>
<representation mediaType="application/vnd.marg.bcsocial.result-v1.9+xml; charset=utf-8" element="web:Result_1" xmlns:web="https://someurl.com/Sdk/WebService"/>
</response>
<response status="200">
<representation mediaType="application/vnd.marg.bcsocial.api.index.options.list-v2.6+xml; charset=utf-8" element="web:ListOfApiIndexOptions_4" xmlns:web="https://someurl.com/Sdk/WebService"/>
<representation mediaType="" element="data"/>
</response>
</method>
</resource>
</resources>
</application>
So I am trying to use this to log on. At the moment, I am trying something like the following
public function updateApi(){
$service_url = 'https://someurl.com/sdk/user/session/logon';
$curl = curl_init($service_url);
$curl_post_data = array(
"ApiKey" => 'somekey',
"ApiSecret" => 'somesecret',
);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
$curl_response = curl_exec($curl);
curl_close($curl);
var_dump($curl_response);
}
However, I always receive a fault response that the login has failed. Do I have to call the logon method or something?
Really just looking for some advice as to whether I am doing things correctly.
Thanks
You don't set the Content-Type header telling the format of the content you posted:
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/x-www-form-urlencoded'));
Otherwise, from php5 upwards, the usage of http_build_query is recommended:
$curl_post_data = array(
"ApiKey" => 'somekey',
"ApiSecret" => 'somesecret',
);
curl_setopt($curl, CURLOPT_POSTFIELDS,
http_build_query($curl_post_data));
Hope it helps you,
Thierry
According the XML you should try to send your curl_post_data variable as a URL Encoded string. like urlencode('ApiKey=somekey&ApiSecret=somesecret') and secondly try to set the content-type of your request to 'application/x-www-form-urlencoded'
$service_url = 'https://someurl.com/sdk/user/session/logon';
$curl = curl_init($service_url);
$headers = ["Content-Type: application/json"]; // or other supported media type
$curl_post_data = array(
"ApiKey" => 'somekey',
"ApiSecret" => 'somesecret',
);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
curl_setopt($rest, CURLOPT_HTTPHEADER,$headers);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$curl_response = curl_exec($curl);
curl_close($curl);

PHP SOAP/CURL Request returns error

Situation: I am having to submit SOAP data to a remote server. The first request is for a URL that is needed for the second request. The URL returned starts the second request and is supposed to give me a return response of a bunch of user data in XML format.
Problem: I am getting an error back from the server on the second request (the data) that is referring to a C# problem and I do not know how to get around this. The error that I am trying to troubleshoot is:
The conversion could not be completed because the supplied DateTime
did not have the Kind property set correctly
HERE IS MY CODING
PHP:
error_reporting(E_ALL);
$soapUrl = "https://domain.com/insidews/insidews.asmx";
$soapUser = "*******";
$soapPassword = "***************************";
// xml post structure
$xml_post_string = '<?xml version="1.0" encoding="utf-8"?>
<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/">
<soap:Header>
<inCredentials xmlns="http://inlogin.com/inSideWS">
<busNo>****************</busNo>
<password>******************</password>
</inCredentials>
</soap:Header>
<soap:Body>
<GetURL xmlns="http://inlogin.com/inSideWS" />
</soap:Body>
</soap:Envelope>';
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"SOAPAction: http://inlogin.com/inSideWS/GetURL",
"Content-length: ".strlen($xml_post_string),
); //SOAPAction: your op URL
$url = $soapUrl;
$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);
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);
if(curl_errno($ch)){
echo 'Curl error: ' . curl_error($ch);
}
curl_close($ch);
//echo $response;
// converting
$response1 = str_replace("<soap:Body>","",$response);
$response2 = str_replace("</soap:Body>","",$response1);
$parser = new SimpleXmlElement($response2);
foreach($parser as $p) {
foreach($p as $n) {
$new_url = $n;
}
}
$timezone = new DateTimeZone('UTC');
$dateone = '12/1/2013 00:00:00';
$startdate = new DateTime($dateone,$timezone);
$startdate = $startdate->format('c');
echo "Start Date: ".$startdate."<br><br>";
$datetwo = '12/31/2013 23:59:59';
$enddate = new DateTime($datetwo,$timezone);
$enddate = $enddate->format('c');
echo "End Date: ".$enddate."<br><br>";
echo "<font style='font-size: 18px; font-weight: bold; text-decoration: underline;'>FILE GET Destination URL:</font> ".$new_url."<br><br>";
$xml_post_string_2 = '<?xml version="1.0" encoding="utf-8"?>
<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/">
<soap:Header>
<inCredentials xmlns="http://inlogin.com/inSideWS">
<busNo>**************</busNo>
<password>*******************************</password>
<timeZoneName>UTC</timeZoneName>
</inCredentials>
</soap:Header>
<soap:Body>
<DataDownloadReport_Run xmlns="http://inlogin.com/inSideWS">
<reportNo>16</reportNo>
<startDate>'.$startdate.'</startDate>
<endDate>'.$enddate.'</endDate>
</DataDownloadReport_Run>
</soap:Body>
</soap:Envelope>';
$new_headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"SOAPAction: http://inlogin.com/inSideWS/DataDownloadReport_Run",
"Content-length: ".strlen($xml_post_string_2),
);
// PHP cURL for https connection with auth
$cho = curl_init();
curl_setopt($cho, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($cho, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($cho, CURLOPT_URL, $new_url);
curl_setopt($cho, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
curl_setopt($cho, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cho, CURLOPT_USERPWD, $soapUser.":".$soapPassword);
curl_setopt($cho, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($cho, CURLOPT_TIMEOUT, 10);
curl_setopt($cho, CURLOPT_POST, true);
curl_setopt($cho, CURLOPT_POSTFIELDS, $xml_post_string_2); // the SOAP request
curl_setopt($cho, CURLOPT_HTTPHEADER, $new_headers);
// converting
$second_response = curl_exec($cho);
// var_dump($second_response);
// var_dump(curl_getinfo($cho));
// var_dump(curl_error($cho));
if(curl_errno($cho)){
echo '<br><br>Curl error: ' . curl_error($cho);
}
//echo $second_response;
print_r($second_response);
curl_close($cho);
// converting
$new_response1 = str_replace("<soap:Body>","",$second_response);
$new_response2 = str_replace("</soap:Body>","",$new_response1);
// convertingc to XML
$new_parser = simplexml_load_string($second_response);
OUTPUT:
Start Date: 2013-12-01T00:00:00+00:00
End Date: 2013-12-31T23:59:59+00:00
FILE GET Destination URL: https://domain.com/inSideWS/inSideWS.asmx
string(0) "" soap:ServerSystem.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.ArgumentException: The conversion could not be completed because the supplied DateTime did not have the Kind property set correctly. For example, when the Kind property is DateTimeKind.Local, the source time zone must be TimeZoneInfo.Local. Parameter name: sourceTimeZone at System.TimeZoneInfo.ConvertTime(DateTime dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone, TimeZoneInfoOptions flags) at System.TimeZoneInfo.ConvertTimeFromUtc(DateTime dateTime, TimeZoneInfo destinationTimeZone) at UCN.Common.TimeZoneUtilities.ConvertUTCToTimeZone(DateTime time, String id) in d:\Agents\7\inContact\RC-Web.inSideWS\Sources\C#\Library\Common\Utilities\TimeZoneUtilities.cs:line 109 at inContact.DataDownload.Report.GetData(String dataSourceModule, Int32 reportType) in d:\Agents\7\inContact\RC-Web.inSideWS\Sources\C#\Library\inContact.DataDownload\Report.cs:line 128 at inContact.DataDownload.Report.RunReport(Nullable`1 busNo, Nullable`1 reportNo, Nullable`1 maximumRows, Nullable`1 startIndex, String orderColumn, Nullable`1 orderASC, String searchText, Nullable`1& rowCount) in d:\Agents\7\inContact\RC-Web.inSideWS\Sources\C#\Library\inContact.DataDownload\Report.cs:line 78 at inSideWebService.inSideWS.DataDownloadReport_Run(Int32 reportNo, DateTime startDate, DateTime endDate) --- End of inner exception stack trace ---
I have fixed the issue. Translating the DateTime from PHP to C# should have worked but for some reason C# was not accepting the ISO8601 format like it was supposed to (as I was told it did). So I simply changed the following coding for the date:
$timezone = new DateTimeZone('UTC');
$time = time("00:00:00");
$dateone = '12/1/2013 00:00:00';
$startdate = date("Y-m-d", strtotime($dateone)) . 'T' . date("H:i:s", strtotime($dateone));
$datetwo = '12/31/2013 23:59:59';
$enddate = date("Y-m-d", strtotime($datetwo)) . 'T' . date("H:i:s", strtotime($datetwo));
This fixed the problem and I am now getting a response from the server.
Have you tried making the call using PHPs soap library, it takes care of most of the headers and intricacies associated with SOAP. The documentation is here http://www.php.net/manual/en/book.soap.php.

how to post xmldata to an https:// wsdl via php

Good Evening All,
I am been fighting an uphill battle try to post xml data to an https web service. I am new to PHP so I am trying to learn as I go. I have been able to post the xml data to the web services via soapUI but I cannot recreate to process thru PHP. If anyone who a PHP SOAP guru could explain to me what I am doing wrong that would be a great help. Below is the code snippet I am trying to post to the web service.
<?php
$user = "xxxxxx";
$password = "xxxxx";
$url = "https://esws.energystar.gov/DataServices/servlet/webservices?ver=1.1&wsdlxml";
$post_string = <<<EOT
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:roof="http://www.energystar.gov/schema/Roof_Products_2_x/" xmlns:core="http://www.energystar.gov/schema/core/">
<soapenv:Header/>
<soapenv:Body>
<roof:Roof_Products_submission>
<core:core_submission>
<core:Authentication_UserName>xxxxx</core:Authentication_UserName>
<core:Authentication_Password>xxxxxxx</core:Authentication_Password>
<core:Certification_Body_EPA_Issued_Organization_Id>xxxxxxx</core:Certification_Body_EPA_Issued_Organization_Id>
<core:Is_Test_Submission>Yes</core:Is_Test_Submission>
</core:core_submission>
<!--1 or more repetitions:-->
<roof:Roof_Products>
<core:core_product_data>
<core:ENERGY_STAR_Manufacturing_Partner>QPX Active Partner</core:ENERGY_STAR_Manufacturing_Partner>
<core:ENERGY_STAR_Manufacturing_Partner_s_EPA_issued_Organization_ID>xxxxxxxxx</core:ENERGY_STAR_Manufacturing_Partner_s_EPA_issued_Organization_ID>
<core:Partner_Contact_Name_For_This_Model>xxxxxxx</core:Partner_Contact_Name_For_This_Model>
<core:Type_of_Transaction>Initial Certification</core:Type_of_Transaction>
<core:Reason_for_Transaction>Initial Certification: Model Meets ENERGY STAR Requirements</core:Reason_for_Transaction>
<core:Date_of_Transaction_Type>2010-12-31</core:Date_of_Transaction_Type>
<core:ENERGY_STAR_Model_Identifier>TestID2929</core:ENERGY_STAR_Model_Identifier>
<core:Certification_ID>TestCertID123</core:Certification_ID>
<core:Family_ID>TestFamID123</core:Family_ID>
<core:Model_Name>Model_Name1234</core:Model_Name>
<core:Model_Number>Model_Number33453</core:Model_Number>
<core:Brand_Name>Brand_Name1</core:Brand_Name>
<core:Tested_Model_Name>Tested_Model_Name1</core:Tested_Model_Name>
<core:Tested_Model_Number>Tested_Model_Number1</core:Tested_Model_Number>
<!--Zero or more repetitions:-->
<core:Additional_Models_Represented_by_Family_Series_or_DOE_Basic>
<core:Additional_Model_Name>test</core:Additional_Model_Name>
<core:Additional_Model_Number>12345</core:Additional_Model_Number>
<core:Additional_Identifying_Information>non</core:Additional_Identifying_Information>
</core:Additional_Models_Represented_by_Family_Series_or_DOE_Basic>
<core:Is_the_Partner_Listed_the_Original_Equipment_Manufacturer_OEM>Yes</core:Is_the_Partner_Listed_the_Original_Equipment_Manufacturer_OEM>
<core:If_the_Partner_is_Not_the_Original_Equipment_Manufacturer_Who_is>?</core:If_the_Partner_is_Not_the_Original_Equipment_Manufacturer_Who_is>
<core:Currently_Available_on_Market>Yes</core:Currently_Available_on_Market>
<core:Date_Available_On_Market>2010-12-31</core:Date_Available_On_Market>
<core:Date_Tested>2010-12-31</core:Date_Tested>
<core:Date_CB_Notified_Partner_of_Model_Qualification>2010-12-31</core:Date_CB_Notified_Partner_of_Model_Qualification>
<core:Certification_Body_Contact_Name_for_This_Model>QPX Certification Body 1</core:Certification_Body_Contact_Name_for_This_Model>
<!--Zero or more repetitions:-->
<core:Laboratory>
<core:Laboratory_EPA_issued_Organization_ID>xxxxxxxxx</core:Laboratory_EPA_issued_Organization_ID>
<core:Laboratory_Contact_for_This_Model>QPX Laboratory Test</core:Laboratory_Contact_for_This_Model>
</core:Laboratory>
<!--1 to 8 repetitions:-->
<core:To_What_Major_Markets_is_This_Model_Sold>United States</core:To_What_Major_Markets_is_This_Model_Sold>
<core:Notes>notes on the product</core:Notes>
</core:core_product_data>
<roof:ENERGY_STAR_Specification_Version>2.2</roof:ENERGY_STAR_Specification_Version>
<roof:Product_Type>Single-Ply</roof:Product_Type>
<roof:Measured_Initial_Solar_Reflectance>0.25</roof:Measured_Initial_Solar_Reflectance>
<roof:Reported_Initial_Solar_Reflectance>0.26</roof:Reported_Initial_Solar_Reflectance>
<roof:Initial_Solar_Reflectance_Test_Method>ASTM E903-96</roof:Initial_Solar_Reflectance_Test_Method>
<roof:Measured_Solar_Reflectance_After_Three_Years>0.15</roof:Measured_Solar_Reflectance_After_Three_Years>
<roof:Reported_Reflectance_After_Three_Years>0.16</roof:Reported_Reflectance_After_Three_Years>
<roof:Solar_Reflectance_After_Three_Years_Test_Method>ASTM C1549-09</roof:Solar_Reflectance_After_Three_Years_Test_Method>
<roof:Measured_Initial_Emissivity>0.01</roof:Measured_Initial_Emissivity>
<roof:Reported_Initial_Emissivity>0.02</roof:Reported_Initial_Emissivity>
<roof:Initial_Emissivity_Test_Method_Used>ASTM E408-71(1996) e1</roof:Initial_Emissivity_Test_Method_Used>
<roof:Low_Slope>Yes</roof:Low_Slope>
<roof:Steep_Slope>Yes</roof:Steep_Slope>
<roof:Roof_Cleaned_Prior_to_Third_Year_Test>No</roof:Roof_Cleaned_Prior_to_Third_Year_Test>
<roof:Warranty_Period>abcdefg</roof:Warranty_Period>
</roof:Roof_Products>
</roof:Roof_Products_submission>
</soapenv:Body>
</soapenv:Envelope>
EOT;
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, $url );
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, array('Content-Type: text/xml; charset=utf-8', 'Content-Length: '.strlen($post_string) ));
curl_setopt($soap_do, CURLOPT_USERPWD, $user . ":" . $password);
$result = curl_exec($soap_do);
$err = curl_error($soap_do);
?>
Any and all help would be greatly appreciated.
I'm not sure, if this is correct, but it should be something along these lines:
$namespace = 'https://esws.energystar.gov';
$auth = new ChannelAdvisorAuth($user, $password);
$header = new SoapHeader($namespace, 'APICredentials', $auth, false);
$soap = new SoapClient($url);
$soap->__setSoapHeaders($header);
$soap->DataServices_Server($post_string);
I hope this will point you in the right direction :)

Categories