I am getting an error "Unable to get Client ID" while initiating the call from Twilio API via JavaScript SDK.
Here is the PHP Code
$callerId = "+1xxxxxxxxxx";
if (isset($_REQUEST['PhoneNumber'])) {
$number = htmlspecialchars($_REQUEST['PhoneNumber']);
}
if (preg_match("/^[\d\+\-\(\) ]+$/", $number)) {
$numberOrClient = "<Number>" . $number . "</Number>";
} else {
$numberOrClient = "<Client>" . $number . "</Client>";
}
$xml = '<Response>
<Dial callerId="'.$callerId.'">
'.$numberOrClient.'
</Dial>
<Record timeout="1000" transcribe="true" />
</Response>';
Here is the error screenshot
It seems $number is an empty string when you call the function and this produces invalid TwiML.
According to the documentation, the <Client> tag needs to contain a string or several tags to specify the clientId.
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial>
<Client>
<Identity>user_jane</Identity>
<Parameter name="FirstName" value ="Jane"/>
<Parameter name="LastName" value ="Doe" />
</Client>
</Dial>
</Response>
or
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial>
<Client>joey</Client>
</Dial>
</Response>
Related
i am trying to parse the xml data from the result of my payment page, here is my code
$text = '<?xml version="1.0" encoding="utf-8"?>
<Exception xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Error xsi:type="BBSException">
<Message>Unable to auth</Message>
<Result>
<IssuerId>3</IssuerId>
<ResponseCode>98</ResponseCode>
<ResponseText>Transaction already processed</ResponseText>
<ResponseSource>Netaxept</ResponseSource>
<TransactionId>52ca86375c18468d8d7425c7a53459e1</TransactionId>
<ExecutionTime>2018-05-23T14:16:48.6230323+02:00</ExecutionTime>
<MerchantId>718374</MerchantId>
<ExtraInfoOut>2030010</ExtraInfoOut>
<MaskedPan />
<MessageId>ccf05c6e0bd84e77862431ac22140d7c</MessageId>
</Result>
</Error>
</Exception>';
$xml = simplexml_load_string($text);
echo "my message is".$xml->Error->Message."<br>";
echo "my response code is".$xml->Error->Result->ResponseCode."<br>";
This code works fine and return the result as
my message is Unable to auth
my response code is 98
but when i am trying to get this result from the payment result page like this
$text = file_get_contents("https://xxxx/xxxxx/xxxxxx");
$xml = simplexml_load_string($text);
echo "my message is".$xml->Error->Message."<br>";
echo "my response code is".$xml->Error->Result->ResponseCode."<br>";
but this code is not returning the value from the xml, when the i print the $text, it show the xml output
<?xml version="1.0" encoding="utf-8"?>
<Exception xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Error xsi:type="BBSException">
<Message>Unable to auth</Message>
<Result>
<IssuerId>3</IssuerId>
<ResponseCode>98</ResponseCode>
<ResponseText>Transaction already processed</ResponseText>
<ResponseSource>Netaxept</ResponseSource>
<TransactionId>52ca86375c18468d8d7425c7a53459e1</TransactionId>
<ExecutionTime>2018-05-23T14:16:48.6230323+02:00</ExecutionTime>
<MerchantId>718374</MerchantId>
<ExtraInfoOut>2030010</ExtraInfoOut>
<MaskedPan />
<MessageId>ccf05c6e0bd84e77862431ac22140d7c</MessageId>
</Result>
</Error>
</Exception>
can you any one help me with this
Thanks in advance
$sXML = file_get_contents('xxxxxx');
$oXML = new SimpleXMLElement($sXML);
echo $oXML->Error->Result->ResponseCode;
I have oai.php page.Now when i type in url oai.php?verb=identify then want to show the contents in identify.xml.But i want the same url(oai.php?verb=identify) when i view the identify.xml.Below code showing only data of xml.
<?php
include "config.php";
$id= $_GET['verb'];
//echo $id;
if($id=="identify")
{
$date_mod = gmdate("Y-m-d\TH:i:s\Z");
$rss_txt ='<?xml version="1.0" encoding="utf-8"?>
<OAI-PMH xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.openarchives.org/OAI/2.0/" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
<responseDate>' .$date_mod. '</responseDate>
<request verb="Identify">http://mywebsite.org/oai</request>
<Identify>
<repositoryName>mydomain</repositoryName>
<baseURL>mywesite.com</baseURL>
<protocolVersion>2.0</protocolVersion>
<adminEmail>myemail</adminEmail>
<earliestDatestamp>'.$date_mod.'</earliestDatestamp>
<deletedRecord>transient</deletedRecord>
<granularity>YYYY-MM-DDThh:mm:ssZ</granularity>
</Identify>
</OAI-PMH>';
}
else if($id=="ListRecords")
{
include "config.php";
$date_mod = gmdate("Y-m-d\TH:i:s\Z");
$viewss1=$con->query("SELECT COUNT(upload_paper_id) FROM upload_papers");
$cview1=$viewss1->fetch_row();
$countt1=$cview1[0];
$rss_txt = '<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="http://localhost/oai-file/data/oai2.xsl" ?>
<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
<responseDate>' .$date_mod. '</responseDate>
<request verb="ListRecords" metadataPrefix="oai_dc">http:mywebsite.org</request>
<ListRecords>';
$query = "SELECT * FROM upload_papers";
$result=$con->query($query);
while($values_query = mysqli_fetch_assoc($result))
{
$year= $values_query['year'];
$upload_paper_id= $values_query['upload_paper_id'];
$rss_txt = '<record>
<header>
<identifier>' .$upload_paper_id. '</identifier>
<datestamp>' .$date_mod. '</datestamp>
<setSpec>mydoc8:BIH</setSpec>
</header>
<metadata>
<oai_dc:dc
xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/
http://www.openarchives.org/OAI/2.0/oai_dc.xsd">
<dc:title xml:lang="en-US">' .$values_query['paper_title']. '</dc:title>
<dc:creator>' . $values_query['author_name']. '</dc:creator>
<dc:creator>' . $values_query['co_author_name']. '</dc:creator>
<dc:description xml:lang="en-US">' .$values_query['abstract']. '</dc:description>
<dc:publisher xml:lang="en-US">' .$values_query['journal_nam']. '</dc:publisher>
<dc:contributor xml:lang="en-US">' .$values_query['author_name']. '</dc:contributor>
<dc:type xml:lang="en-US">Article</dc:type>
<dc:format>application/pdf</dc:format>
<dc:identifier>http://mywebsite'.$year.'/article.php?page='.$upload_paper_id.'</dc:identifier>
<dc:language>en</dc:language>
</oai_dc:dc>
</metadata>
</record>';
}
$rss_txt = '<resumptionToken
completeListSize="'.$countt1.'"
cursor="0">'.$date_mod.'</resumptionToken>
</ListRecords>
</OAI-PMH>';
}
else if($id=="ListSets")
{
$rss_txt =file_get_contents("ListSets.xml");
}
header('Content-type: application/xml');
echo $rss_txt;
?>
Above code shows only the data of xml.The output attached below
And i want the output like
.If i type verb=identify in url then it want to show identify.xsd or xml file any one.Then i type Listsets Want to show the content in that page.if verb equal to empty want to show the identify page.Please help me.Its really irritating me.Thank u
There are a few problems with the code. The main thing is to set your header to be XML content type. This will tell the browser what to expect. But there are a few other issues.
$id= $_GET['verb'];
//echo $id;
if($id=="identify")
{
$date_mod = gmdate("Y-m-d\TH:i:s\Z");
$rss_txt ='<?xml version="1.0" encoding="utf-8"?>
<OAI-PMH xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.openarchives.org/OAI/2.0/" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
<responseDate>' .$date_mod. '</responseDate>
<request verb="Identify">http://mywebsite.org/oai</request>
<Identify>
<repositoryName>mydomain</repositoryName>
<baseURL>mywesite.com</baseURL>
<protocolVersion>2.0</protocolVersion>
<adminEmail>myemail</adminEmail>
<earliestDatestamp>'.$date_mod.'</earliestDatestamp>
<deletedRecord>transient</deletedRecord>
<granularity>YYYY-MM-DDThh:mm:ssZ</granularity>
</Identify>
</OAI-PMH>';
}
else if($id=="ListRecords")
{
$rss_txt =file_get_contents("compend1.xml");
}
else if($id=="ListSets")
{
$rss_txt =file_get_contents("ListSets.xml");
}
header('Content-type: application/xml');
echo $rss_txt;
You had $rss_txt .= which with the . means append the string, which as you didn't declare it anywhere gives you the error about an undefined variable. Also with the content - XML needs to start right at the beginning of the string, so remove the whitespace.
The main one is having...
header('Content-type: application/xml');
But, for this to work properly, you need to ensure you comment out the echo, which I assume was some debugging code.
When doing an if - a single = is used to assign a value, so you need == to compare the values.
You can use $_GET[] to access the parameters rather than the way you were using, a lot simpler.
I've used file_get_contents() to fetch the data from those other files and moved the echo to the end so they all have the same logic.
Response from CURL request:
<?xml version="1.0" encoding="UTF-8"?>
<soap-env:envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:header>
<soap-env:body>
<ipgapi:ipgapiorderresponse xmlns:ipgapi="http://ipg-online.com/ipgapi/schemas/ipgapi" xmlns:a1="http://ipg-online.com/ipgapi/schemas/a1" xmlns:v1="http://ipg-online.com/ipgapi/schemas/v1">
<ipgapi:approvalcode>Y:761862:4515799310:PPXP:0037</ipgapi:approvalcode>
<ipgapi:avsresponse>PPX</ipgapi:avsresponse>
<ipgapi:brand>VISA</ipgapi:brand>
<ipgapi:country>GBR</ipgapi:country>
<ipgapi:commercialserviceprovider>BOSMS</ipgapi:commercialserviceprovider>
<ipgapi:orderid>A-966025d3-81a2-453a-820e-bb145e8390d1</ipgapi:orderid>
<ipgapi:ipgtransactionid>84515799310</ipgapi:ipgtransactionid>
<ipgapi:paymenttype>CREDITCARD</ipgapi:paymenttype>
<ipgapi:processorapprovalcode>761862</ipgapi:processorapprovalcode>
<ipgapi:processorccvresponse>P</ipgapi:processorccvresponse>
<ipgapi:processorreferencenumber>761862</ipgapi:processorreferencenumber>
<ipgapi:processorresponsecode>00</ipgapi:processorresponsecode>
<ipgapi:processorresponsemessage>AUTH CODE:761862</ipgapi:processorresponsemessage>
<ipgapi:tdate>1521047872</ipgapi:tdate>
<ipgapi:tdateformatted>2018.03.14 18:17:52 (CET)</ipgapi:tdateformatted>
<ipgapi:terminalid>21400371</ipgapi:terminalid>
<ipgapi:transactionresult>APPROVED</ipgapi:transactionresult>
<ipgapi:transactiontime>1521047872</ipgapi:transactiontime>
</ipgapi:ipgapiorderresponse>
</soap-env:body>
</soap-env:header>
</soap-env:envelope>
I've tried the following:
$responseXML = '<?xml version="1.0" encoding="UTF-8"?>
<soap-env:envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:header>
<soap-env:body>
<ipgapi:ipgapiorderresponse xmlns:ipgapi="http://ipg-online.com/ipgapi/schemas/ipgapi" xmlns:a1="http://ipg-online.com/ipgapi/schemas/a1" xmlns:v1="http://ipg-online.com/ipgapi/schemas/v1">
<ipgapi:approvalcode>Y:761862:4515799310:PPXP:0037</ipgapi:approvalcode>
<ipgapi:avsresponse>PPX</ipgapi:avsresponse>
<ipgapi:brand>VISA</ipgapi:brand>
<ipgapi:country>GBR</ipgapi:country>
<ipgapi:commercialserviceprovider>BOSMS</ipgapi:commercialserviceprovider>
<ipgapi:orderid>A-966025d3-81a2-453a-820e-bb145e8390d1</ipgapi:orderid>
<ipgapi:ipgtransactionid>84515799310</ipgapi:ipgtransactionid>
<ipgapi:paymenttype>CREDITCARD</ipgapi:paymenttype>
<ipgapi:processorapprovalcode>761862</ipgapi:processorapprovalcode>
<ipgapi:processorccvresponse>P</ipgapi:processorccvresponse>
<ipgapi:processorreferencenumber>761862</ipgapi:processorreferencenumber>
<ipgapi:processorresponsecode>00</ipgapi:processorresponsecode>
<ipgapi:processorresponsemessage>AUTH CODE:761862</ipgapi:processorresponsemessage>
<ipgapi:tdate>1521047872</ipgapi:tdate>
<ipgapi:tdateformatted>2018.03.14 18:17:52 (CET)</ipgapi:tdateformatted>
<ipgapi:terminalid>21400371</ipgapi:terminalid>
<ipgapi:transactionresult>APPROVED</ipgapi:transactionresult>
<ipgapi:transactiontime>1521047872</ipgapi:transactiontime>
</ipgapi:ipgapiorderresponse>
</soap-env:body>
</soap-env:header>
</soap-env:envelope>';
$xml = simplexml_load_string($responseXML);
print_r($xml);
// Returns empty object
I've also tried the following:
$xml = new SimpleXMLElement($responseXML);
print_r($xml);
// This also returns empty object
Could someone help me figure out what's going wrong with this?
Using print_r(); with a SimpleXMLElement usually doesn't give anything useful. Instead you should use asXML() which outputs the original XML.
$xml = simplexml_load_string($responseXML);
echo $xml->asXML();
Which gives
<?xml version="1.0" encoding="UTF-8"?>
<soap-env:envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:header>
<soap-env:body>
...
You can access the data by using something like...
$xml = simplexml_load_string($responseXML);
$body = $xml->xpath("//soap-env:body");
$bodyData = $body[0]->children("ipgapi", true);
echo $bodyData->ipgapiorderresponse->approvalcode;
So $bodyData is the <ipgapi:ipgapiorderresponse ...> element and so accessing each part of that is by using the last line. You can use the element name (minus the namespace prefix ipgapi as this is taken care of with the children() call earlier). That line outputs
Y:761862:4515799310:PPXP:0037
I am trying to parse a soap response with simplexml_load_string(). I have my soap client set with trace = 1 and exceptions = 0 and $client->__getLastResponse() gives me this result:
<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV = "http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<MDHeader>
<userid>inspector#prime.com</userid>
<password>prime123456</password>
<batchid>1234</batchid></MDHeader>
<RECORDSET>
<ROW id='0'>
<INSPECTIONS>
<FOLDER_ID>835410936</FOLDER_ID>
<FOLDER_ID>835221706</FOLDER_ID>
<FOLDER_ID>835222299</FOLDER_ID>
</INSPECTIONS>
</ROW>
</RECORDSET>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I then read the results into $xml:
$xml = "<?xml version='1.0' encoding='UTF-8'?>";
$xml .= urldecode($client->__getLastResponse());
An finally try to echo an element with no luck:
$xml1 = simplexml_load_string($xml,null,null,'http://schemas.xmlsoap.org/soap/envelope/',true);
echo "ELEMENT:" . $xml1->Envelope->Body->MDHeader->userid;
I believe it is the namespace SOAP-ENV that is giving me the issue but I don't know how to resolve it.
You can see my test page at: http://www.primevaluationservices.com/myriad/test.php
I think you don't need this line because it is already in the xml:
$xml = "<?xml version='1.0' encoding='UTF-8'?>";
To get the 'userid', I think you can use the SimpleXMLElement children method:
$source = <<<SOURCE
<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV = "http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<MDHeader>
<userid>inspector#prime.com</userid>
<password>prime123456</password>
<batchid>1234</batchid></MDHeader>
<RECORDSET>
<ROW id='0'>
<INSPECTIONS>
<FOLDER_ID>835410936</FOLDER_ID>
<FOLDER_ID>835221706</FOLDER_ID>
<FOLDER_ID>835222299</FOLDER_ID>
</INSPECTIONS>
</ROW>
</RECORDSET>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
SOURCE;
$xml1 = simplexml_load_string($source);
echo $xml1->children('SOAP-ENV', true)->Body->children('')->MDHeader->userid->__toString();
Or the SimpleXMLElement xpath method:
$elements = $xml1->xpath('//SOAP-ENV:Envelope/SOAP-ENV:Body/MDHeader/userid');
$userid = $elements[0]->__toString();
echo '<br>';
echo $userid;
Will both result in:
inspector#prime.com
Demo
I am wondering why the below code doesn't show the value of processResponse tag while it shows the whole XML and the Body tag.
This is the XML which I am handling
$xml = '<?xml version="1.0"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing">
<env:Header>
<wsa:MessageID>urn:df1231asfer5e4564affds</wsa:MessageID>
<wsa:ReplyTo><wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address></wsa:ReplyTo>
</env:Header>
<env:Body>
<processResponse xmlns="http://xmlns.oracle.com/EligibilityProcess/EligibilityProcess/EligibilityBPEL">
<generatedMessageRefNo>451</generatedMessageRefNo>
<providerRefNo>41</providerRefNo>
<tpaRequestId>4184612387</tpaRequestId>
<contractHolder>Rami Zbeeb</contractHolder>
<contractNo>81456954</contractNo>
<guarantorName>ANC</guarantorName>
<eligibilityStatus>Success</eligibilityStatus>
<eligibilityReason xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<messageOrNotes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<patientShare></patientShare>
<consentForm></consentForm>
<webServTechStatus>Success</webServTechStatus>
<replyCode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<replyDescription xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</processResponse></env:Body></env:Envelope>';
I am using the SimpleXML class:
$res = new SimpleXMLElement($xml);
When I am showing the body XML it works:
$str = $res->children('env',true)->Body->asXML();
echo "<pre>",htmlentities($str),"</pre>";
However when showing the processResponse XML or string it doesn't work:
$str = $res->children('env',true)->Body->processResponse->asXML();
echo "<pre>",htmlentities($str),"</pre>";
Kindly advice.
You can get the children of Body to get the processResponse:
$str = $res->children('env',true)->Body->children()->processResponse->asXML();
echo "<pre>",htmlentities($str),"</pre>";