How do I read this soap response and echo the values of subid and points.
Here is the response
<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:zuku">
<SOAP-ENV:Body>
<ns1:showloyaltypointsResponse xmlns:ns1="http://tempuri.org">
<return xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:subpoints[1]">
<item xsi:type="tns:subpoints">
<subid xsi:type="xsd:integer">618341</subid>
<points xsi:type="xsd:string">0</points>
</item>
</return>
</ns1:showloyaltypointsResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
And here is my php code
$result = $client ->call('showloyaltypoints',array("subid" =>$subid,"username" =>"$username", "password" =>"$password"));
echo $client->response;
I found out the solution by converting it to an array first.
https://stackoverflow.com/a/42311833/7042343
Related
Hi I want to get value from given XML using simple_xml_string but its not working. XML is given below:
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Header>
<eb:MessageHeader xmlns:eb="http://www.ebxml.org/namespaces/messageHeader" eb:version="1.0" soap-env:mustUnderstand="1">
<eb:From><eb:PartyId eb:type="urn:x12.org.IO5:01">webservices.sabre.com</eb:PartyId></eb:From>
<eb:To><eb:PartyId eb:type="urn:x12.org.IO5:01">info#gandakiintl.com</eb:PartyId></eb:To>
<eb:CPAId>T198</eb:CPAId>
<eb:ConversationId>111#gandakiintl.com</eb:ConversationId>
<eb:Service eb:type="SabreXML">Enhanced Air Book Request</eb:Service>
<eb:Action>ErrorRS</eb:Action>
<eb:MessageData>
<eb:MessageId>1522435489615361760</eb:MessageId>
<eb:Timestamp>2017-01-11T13:36:01</eb:Timestamp>
<eb:RefToMessageId>mid:11110info#gandakiintl.com</eb:RefToMessageId>
</eb:MessageData>
</eb:MessageHeader>
<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext">
<wsse:BinarySecurityToken valueType="String" EncodingType="wsse:Base64Binary">
Shared/IDL:IceSess\/SessMgr:1\.0.IDL/Common/!ICESMS\/ACPCRTC!ICESMSLB\/CRT.LB!-3319706757025363837!367706!0
</wsse:BinarySecurityToken>
</wsse:Security>
</soap-env:Header>
<soap-env:Body>
<soap-env:Fault>
<faultcode>soap-env:Client.InvalidSecurityToken</faultcode>
<faultstring>Invalid or Expired binary security token: Shared/IDL:IceSess\/SessMgr:1\.0.IDL/Common/!ICESMS\/ACPCRTC!ICESMSLB\/CRT.LB!-3319706757025363837!367706!0</faultstring>
<detail>
<StackTrace>
com.sabre.universalservices.base.session.SessionException: errors.session.USG_INVALID_SECURITY_TOKEN
</StackTrace>
</detail>
</soap-env:Fault>
</soap-env:Body>
</soap-env:Envelope>
From above xml I want to get faultCode node value But I am not able to get. Please help. I tried doing it but its not working.
$feed = simplexml_load_string($response);
$a = $feed->children('http://schemas.xmlsoap.org/soap/envelope/');
var_dump($a->Fault->children('http://schemas.xmlsoap.org/soap/envelope/'));
Edited:
Output I get is: Node no longer exists. But I want to get "soap-env:Client.InvalidSecurityToken" value.
I want to transform my SOAP request from key-value format to another:
<SOAP-ENV:Header>
<ns2:AUTH>
<item>
<key>username</key>
<value>testuser</value>
</item>
<item>
<key>password</key>
<value>xxxxx</value>
</item>
</ns2:AUTH>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:getProductConfig/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
This is what I want:
<SOAP-ENV:Header>
<ns2:AUTH>
<username>testuser</username>
<password>xxxxx</password>
</ns2:AUTH>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:getProductConfig>
<partner_id>1</partner_id>
</ns1:getProductConfig>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
This is my PHP code where I create a new SoapClient object:
$header = new SoapHeader('chainstore-api','AUTH',$headerOptions, FALSE);
$req = new SoapClient(NULL, $options);
$req->__setSoapHeaders($header);
$res = $req->getProductConfig($params);
echo $res;
PS: Currently, It's non wsdl style but I'm thinking about to change to use wsdl too.
This may sound crazy, but I just fixed this by using WSDL instead.
It is much easier. WSDL file will determine both SOAP request and response.
How can i get errorCode and errorMsg values? I went trough many example but still struggling.
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:doOperationsResponse xmlns:ns1="urn:bulkdeployer.easy.gintel.com" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<result href="#id0"/>
</ns1:doOperationsResponse>
<multiRef xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="urn:bulkdeployer.easy.gintel.com" id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:ResponseType">
<errorCode xsi:type="xsd:int">0</errorCode>
<errorMsg xsi:type="xsd:string">No errors</errorMsg>
</multiRef>
</soapenv:Body>
</soapenv:Envelope>
What I have tried:
$xml= simplexml_load_string($content);
$xml->registerXPathNamespace('nam','urn:bulkdeployer.easy.gintel.com'); // need to register namespace
$return_code = $xml->xpath('//nam:errorCode');
$return_msg = $xml->xpath('//nam:errorMsg');
Thanks
I have XML document captured from a link and anytime I use simplexml_load_file(), it gives me an error saying *Warning: simplexml_load_file(): https://kga-dev.mirakl.net/api/shops?:1: parser error : Start tag expected, '<' not found in C:\wamp\www\merchants\get_merchants.php on line 6*
This is a part of my xml file
<body>
<shops>
<shop>...</shop>
<shop>
<approval_delay xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<approval_rate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<order_messages_response_delay xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<banner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<billing_info>
<bank_city xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<bank_name xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<bank_street xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<zip_code xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<bic xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<iban xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<owner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</billing_info>
And this is my simple php code
<?php
$apiLink = "https://kga-dev.mirakl.net/api/shops?";
$xml=simplexml_load_file($apiLink);
print_r($xml);
//echo $xml->shop_id;
?>
The solution for this problem is, that the API serves a JSON encoded string instead of an XML string. So the delivered content can not be parsed with SimpleXML. Try to get it with the following example
$content = file_get_contents($apiLink);
$data = json_decode($content);
In this case $data should be an object or array with all the data the api delivers.
Are you sure that this is the same XML as returned to the script? Note that you are not calling :1 - I cannot check as it requires authorization, yet in the example given by you there is no error up to line 7 so it would mean that possibly something else is returned as the code below works:
<?php
$s = '<body>
<shops>
<shop>...</shop>
<shop>
<approval_delay xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<approval_rate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<order_messages_response_delay xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<banner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</shop>
</shops>
</body>';
$xml=simplexml_load_string($s);
print_r($xml);
?>
Is not the authorization the problem your end? I need to authorize to your webservice: you handle that in a different way for your IP or something like that?
Your Code
<approval_rate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
use single quotes
<?php
echo "<order_messages_response_delay xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:nil='true'/>";
?>
I'd like to change the tag that is currently 'return' to 'result'. Like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:AuthenticateResponse xmlns:ns1="http://tempuri.org">
<***return***>
<Result xsi:type="xsd:string">OK</Result>
</***return***>
</ns1:AuthenticateResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
(see the value between the ***)
Is this possible? And if so, how?
I've fixed this myself by changing the nusoap.php file (line 4143 like this:
original:
$return_val = $this->serialize_val($this->methodreturn, 'return');
Edited code:
$return_val = $this->serialize_val($this->methodreturn, 'result');
I bet there is a better way of handling this, but this fixes it for me.