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
Related
I have got XML response from curl and trying to search some tag value but I am failing. Kindly somebody help me
Please bare as I am new to the PHP
<?php
$DynamicValue = 'KWI';
$url='https://www.example.com/_api/web/lists/getbytitle(\'Stations\')/items?$select=OfficeId&$filter='.urlencode("CityCode eq '" . $DynamicValue . "'");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: application/xml"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$XML = new SimpleXMLElement($result);
foreach($XML->entry as $value)
{
echo $value->OfficeId
}
Output:
<?xml version="1.0" encoding="utf-8"?><feed xml:base="https://www.example.com/_api/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml"><id>a9f073a2-387e-4ac5-81b9-16b3ae81dba3</id><title /><updated>2017-03-20T08:15:47Z</updated><entry m:etag=""61""><id>Web/Lists(guid'5344b09b-d3f7-44ec-bd52-a8f5a99f23f9')/Items(23)</id><category term="SP.Data.StationsListItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /><link rel="edit" href="Web/Lists(guid'5344b09b-d3f7-44ec-bd52-a8f5a99f23f9')/Items(23)" /><title /><updated>2017-03-20T08:15:47Z</updated><author><name /></author><content type="application/xml"><m:properties><d:OfficeId>KWIKU08AA</d:OfficeId></m:properties></content></entry></feed>
Hope this will work.
$string='<?xml version="1.0" encoding="utf-8"?><feed xml:base="https://www.example.com/_api/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml"><id>a9f073a2-387e-4ac5-81b9-16b3ae81dba3</id><title /><updated>2017-03-20T08:15:47Z</updated><entry m:etag=""61""><id>Web/Lists(guid\'5344b09b-d3f7-44ec-bd52-a8f5a99f23f9\')/Items(23)</id><category term="SP.Data.StationsListItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /><link rel="edit" href="Web/Lists(guid\'5344b09b-d3f7-44ec-bd52-a8f5a99f23f9\')/Items(23)" /><title /><updated>2017-03-20T08:15:47Z</updated><author><name /></author><content type="application/xml"><m:properties><d:OfficeId>KWIKU08AA</d:OfficeId></m:properties></content></entry></feed>';
echo explode("</d:OfficeId>",explode("<d:OfficeId>", $string)[1])[0];
PHP Code demo
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);
I have been working on a SOAP request / response using CURL with PHP, however I can't seem to work out how to extract the Data for the life of me.
Script for SOAP Request
$soapUrl = "https://xml.proveid.experian.com/IDSearch.cfc?wdsl";
// xml post structure
$xml_post_string = "<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:cor='http://corpwsdl.oneninetwo'>
<soapenv:Header/>
<soapenv:Body>
<cor:search soapenv:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
<xml xsi:type='xsd:string'><![CDATA[
<Search xmlns:xsd='https://xml.proveid.experian.com/xsd/Search.xsd'>
<Authentication>
<Username>".$user."</Username>
<Password>".$pw."</Password>
</Authentication>
<CountryCode>GBR</CountryCode>
<Person>
<Name>
<Forename>".$firstName."</Forename>
<Surname>".$secondName."</Surname>
</Name>
<DateOfBirth>".$dob."</DateOfBirth>
</Person>
<Addresses>
<Address Current='1'>
<Premise>".$premise."</Premise>
<Street>".$streetName."</Street>
<PostTown>".$postTown."</PostTown>
<Region/>
<Postcode>".$postCode."</Postcode>
<CountryCode>GBR</CountryCode>
</Address>
</Addresses>
<Telephones>
<Telephone>
<Number>".$telephone."</Number>
</Telephone>
</Telephones>
<IPAddress>127.0.0.1</IPAddress>
<Emails>
<Email>".$email."</Email>
</Emails>
<SearchOptions>
<ProductCode>".$product."</ProductCode>
</SearchOptions>
</Search>]]>
</xml>
</cor:search>
</soapenv:Body>
</soapenv:Envelope>";
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: https://xml.proveid.experian.com/IDSearch.cfc",
"Content-length: ".strlen($xml_post_string),
);
$url = $soapUrl;
// PHP cURL for https connection with auth
$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_TIMEOUT, 100);
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);
print_r($response);`
Response
<Search xmlns:xsd="https://xml.proveid.experian.com/xsd/Search.xsd">
<CountryCode>GBR</CountryCode>
<Person>
<Name><Forename>Baken</Forename>
<Surname>Jorure</Surname>
</Name>
<DateOfBirth>1989-09-09</DateOfBirth>
<Age>26</Age>
</Person>
<Addresses>
<Address Current="1">
<Premise>410</Premise>
<Street>Beuno Terrace</Street>
<PostTown>Beuno</PostTown>
<Region/>
<Postcode>LL545BT</Postcode>
<CountryCode>GBR</CountryCode>
</Address>
</Addresses>
<Telephones>
<Telephone>
<Number>01154567892</Number>
</Telephone>
</Telephones>
<IPAddress>127.0.0.1</IPAddress>
<Emails>
<Email>bakenjorure#www.com</Email>
</Emails>
<SearchOptions>
<ProductCode>ProveID</ProductCode>
</SearchOptions>
<OurReference>B3C369C0-F001-4FB1-80D3-801CB9D872FE</OurReference>
<SearchDate>2015-10-09T23:46:54</SearchDate>
<Result>
<Summary>
<ReportSummary>
<DatablocksSummary>
<DatablockSummary>
<Name>CreditReference</Name>
<Decision/>
</DatablockSummary>
</DatablocksSummary>
</ReportSummary>
<DecisionMatrix Code="ECIGSUAT" Name="Electronic Cigarettes">
<Decision>
<Outcome Type="Primary">0</Outcome>
<Reason>Individuals DOB has not matched to active CAIS
ER or Citizen Card therefore application has been
referred
</Reason>
</Decision>
</DecisionMatrix>
</Summary>
</Result>
</Search>
Now all I really need it the number in the Outcome tags. I've tried so many ways but I just can't seem to get it.
Any help would be much appreciated.
Thanks in advance.
For simplier usage of SOAP, you can use PHP builtin SOAP client.
http://php.net/manual/en/class.soapclient.php
With SoapClient class you could do something like this:
<?php
$soapUrl = "https://xml.proveid.experian.com/IDSearch.cfc?wdsl"
$soapClient = new SoapClient($soapUrl);
$parameters = array();
$result = $soapClient->Search($parameters);
?>
In result you will get native PHP data structure, not plain text XML as in here.
Hi guys can anyone have an idea of how to create this request in php. Am invoking a .net soap web-service.
<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>
<confirmCustomerReq xmlns="http://www.nrs.eskom.co.za/xmlvend/revenue/2.1/schema">
<clientID xmlns="http://www.nrs.eskom.co.za/xmlvend/base/2.1/schema" xsi:type="EANDeviceID" ean="xx" />
<terminalID xmlns="http://www.nrs.eskom.co.za/xmlvend/base/2.1/schema" xsi:type="EANDeviceID" ean="xx" />
<msgID xmlns="http://www.nrs.eskom.co.za/xmlvend/base/2.1/schema" dateTime="xx" uniqueNumber="xx" />
<authCred xmlns="http://www.nrs.eskom.co.za/xmlvend/base/2.1/schema">
<opName>xxx</opName>
<password>xxx##1</password>
</authCred>
<idMethod xmlns:q1="http://www.nrs.eskom.co.za/xmlvend/base/2.1/schema" xsi:type="q1:VendIDMethod">
<q1:meterIdentifier xsi:type="q1:MeterNumber" msno="xx" />
</idMethod>
</confirmCustomerReq>
</soap:Body>
</soap:Envelope>
I tried using SoapClient class and curl but still couldn't get the exact xml below is my the snippet of my code. below was using SoapClient class
array( 'ConfirmCustomerReq'=>array(
'ClientID' =>array('xsi:type'=>"EANDeviceID", 'ean'=>"xxxx"),
'terminalID'=>array('xsi:type'=>"EANDeviceID", 'ean'=>"xxx"),
'authCred' => array(
'opName' => "$this->username",
'password' => "$this->pass"
),
'msgID' => array('dateTime'=>"xxx" ,'uniqueNumber'=>"xxx" ),
'idMethod' => array('xsi:type'=>"q1:VendIDMethod",
'meterIdentifier' =>array( 'xsi:type'=>"q1:MeterNumber" ,'msno'=>"xxx")
)
)
);
and curl
function main(){
$xml ='<?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>
<confirmCustomerReq xmlns="http://www.nrs.eskom.co.za/xmlvend/revenue/2.1/schema">
<clientID xmlns="http://www.nrs.eskom.co.za/xmlvend/base/2.1/schema" xsi:type="EANDeviceID" ean="xx" />
<terminalID xmlns="http://www.nrs.eskom.co.za/xmlvend/base/2.1/schema" xsi:type="EANDeviceID" ean="xx" />
<msgID xmlns="http://www.nrs.eskom.co.za/xmlvend/base/2.1/schema" dateTime="xx" uniqueNumber="xx" />
<authCred xmlns="http://www.nrs.eskom.co.za/xmlvend/base/2.1/schema">
<opName>xxx</opName>
<password>xxx##1</password>
</authCred>
<idMethod xmlns:q1="http://www.nrs.eskom.co.za/xmlvend/base/2.1/schema" xsi:type="q1:VendIDMethod">
<q1:meterIdentifier xsi:type="q1:MeterNumber" msno="xx" />
</idMethod>
</confirmCustomerReq>
</soap:Body>
</soap:Envelope>';
try{
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, "https://www.utilitiesworld.co.za/SecureThirdPartyInterface/VendingService.asmx" );
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
//curl_setopt($soap_do, CURLOPT_CAINFO, 'XXXXXXXXXXXXXX');
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_FRESH_CONNECT, TRUE);
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $xml);
//curl_setopt($soap_do, CURLOPT_HEADER, false);
$xml_result = curl_exec($soap_do);
echo curl_error($soap_do);
//$result=parse_str($xml_result);
//var_dump($xml_result);
curl_close($soap_do);
}
soap client modual is exist in php
http://php.net/manual/en/soapclient.soapclient.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");