soap api able to connect in SoapUI but not in PHP - php

I've been failing to consume a soap webservice with soapClient /nusoap I believe the issue might be with my header but I'm not sure as the error I get back are pretty vague at times.
We've been able to get it to work in SoapUI, which adds some additional things to the header notably this:
<wsa:Action>http://www.property24.com/services/IP24ListingServiceWcf/FetchAgents</wsa:Action><wsa:To>https://www.exdev.property24.com/Services/P24ListingService46.svc</wsa:To>
Its being added in SoapUI automaticaly by checking: add default WSA:to under WS-A
inside the header it also has xmlns:wsa="http://www.w3.org/2005/08/addressing" I dont know how to correctly set this if possible.
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ser="http://www.property24.com/services">
<soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<ser:CredentialsHeader>
<!--Optional:-->
<ser:EMail>..</ser:EMail>
<!--Optional:-->
<ser:Password>..!</ser:Password>
<!--Optional:-->
<ser:UserGroupEmailId>1</ser:UserGroupEmailId>
</ser:CredentialsHeader>
<wsa:Action>http://www.property24.com/services/IP24ListingServiceWcf/FetchAgents</wsa:Action><wsa:To>https://www.exdev.property24.com/Services/P24ListingService46.svc</wsa:To></soap:Header>
<soap:Body>
<ser:FetchAgents>
<!--Optional:-->
<ser:agencyId>..</ser:agencyId>
</ser:FetchAgents>
</soap:Body>
</soap:Envelope>
I'm getting a bad request response which I believe could be due to the header
this is what I've tried:
$headerbody = array(
'EMail' => $username,
'Password' => $password,
'UserGroupEmailId'=> $groupId
);
$headers[] = new SoapHeader('https://www.exdev.property24.com/', 'wsa:Action', "http://www.property24.com/services/IP24ListingServiceWcf/$method");
$headers[] = new SoapHeader('https://www.exdev.property24.com/', 'wsa:To', "https://www.exdev.property24.com/Services/P24ListingService46.svc");
$headers[] = new SoapHeader('https://www.exdev.property24.com/', 'CredentialsHeader', $headerbody);
$client->__setSoapHeaders($headers);
and
$header_part = '<CredentialsHeader><EMail>....</EMail><Password>....</Password><UserGroupEmailId>1</UserGroupEmailId></CredentialsHeader>';
$header_part .= '<wsa:Action>http://www.property24.com/services/IP24ListingServiceWcf/$method</wsa:Action><wsa:To>https://www.exdev.property24.com/Services/P24ListingService46.svc</wsa:To>';
$soap_var_header = new SoapVar($header_part, XSD_ANYXML, null, null, null);
$soap_header = new SOAPHeader('http://www.w3.org/2005/08/addressing', 'wsa',
$soap_var_header);
$client->__setSoapHeaders($soap_header);
I've not had a lot of experience with Soap webservices and have been stuck on this for quite some time thanks guys

construct header object by concatenating with user credentials
$headerStr= '
<ser:CredentialsHeader>
<!--Optional:-->
<ser:EMail>'.$username.'</ser:EMail>
<!--Optional:-->
<ser:Password>'.$password.'</ser:Password>
<!--Optional:-->
<ser:UserGroupEmailId>'.$groupId.'</ser:UserGroupEmailId>
</ser:CredentialsHeader>
<wsa:Action>http://www.property24.com/services/IP24ListingServiceWcf/FetchAgents</wsa:Action><wsa:To>https://www.exdev.property24.com/Services/P24ListingService46.svc</wsa:To>
';
$header= new \SoapHeader('http://www.w3.org/2005/08/addressing',
'wsa',
new \SoapVar($headerStr, XSD_ANYXML),
true
);
then construct SoapClient and set headers and operation name with parameters
$soapclient = new SoapClient($serviceURL,$options);
$soapclient-> __setSoapHeaders($header);
parameters can be sent as dictionary but very important to chang "Request" to be identical to the same name in service contract
$param=array ("Request" => array('agencyId'=>'123'));
$response =$soapclient->FetchAgents( $param);
var_dump(json_encode($response));
echo '<br><br><br>';
$array = json_decode(json_encode($response), true);
print_r($array);
the complete code snippet will be
try {
$options = [
"soap_version" => SOAP_1_2, // SOAP_1_1
'trace' => 1,
'exception' => 1,
'keep_alive' => false,
'connection_timeout' => 500000
];
$headerStr = '
<ser:CredentialsHeader>
<!--Optional:-->
<ser:EMail>' . $username . '</ser:EMail>
<!--Optional:-->
<ser:Password>' . $password . '</ser:Password>
<!--Optional:-->
<ser:UserGroupEmailId>' . $groupId . '</ser:UserGroupEmailId>
</ser:CredentialsHeader>
<wsa:Action>http://www.property24.com/services/IP24ListingServiceWcf/FetchAgents</wsa:Action><wsa:To>https://www.exdev.property24.com/Services/P24ListingService46.svc</wsa:To></soap:Header>
';
$header = new \SoapHeader(
'http://www.w3.org/2005/08/addressing',
'ws',
new \SoapVar($headerStr, XSD_ANYXML),
true
);
$soapclient = new SoapClient($serviceURL, $options);
$soapclient->__setSoapHeaders($header);
$param = array('agencyId' => '123');
$response = $soapclient->FetchAgents($param);
// print the last XML request to compare with the working one in soapUI
echo "REQUEST:\n" . $soapclient->__getLastRequest() . "\n";
var_dump(json_encode($response));
echo '<br><br><br>';
$array = json_decode(json_encode($response), true);
print_r($array);
} catch (Exception $e) {
echo $e->getMessage();
}

Related

Soap request working in SoapUI but not in Wordpress plugin

I've been searching around for a solution to my problem, but to no avail. I'm trying to send a soap request through a Wordpress plugin using the following:
function soapRequest($soapUsername, $soapNonce, $soapDateTime, $soapPassword) {
$wsdl = 'http://www.beautyfort.com/api/wsdl/v2/wsdl.wsdl';
$trace = true;
$exceptions = false;
$client = new SoapClient($wsdl, array('trace' => $trace, 'exceptions' => $exceptions));
// Must be a stdClass (and not an array)
$auth = new stdClass();
$auth->Username = $soapUsername;
$auth->Nonce = $soapNonce;
$auth->Created = $soapDateTime;
$auth->Password = $soapPassword;
$header = new SoapHeader('http://www.beautyfort.com/api/', 'AuthHeader', $auth);
$client->__setSoapHeaders($header);
$xml_array['TestMode'] = 'true';
$xml_array['StockFileFormat'] = 'JSON';
$xml_array['SortBy'] = 'StockCode';
try {
$response = $client->GetStockFile($xml_array);
}
catch (Exception $e) {
log_me("Error!");
log_me($e -> getMessage());
log_me('Last response: '. $client->__getLastResponse());
}
log_me('Last request: '. $client->__getLastRequest());
log_me($response);
}
This produces the following request:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://www.beautyfort.com/api/">
<SOAP-ENV:Header>
<ns1:AuthHeader>
<ns1:Username>joetest</ns1:Username>
<ns1:Nonce>htflFfIKM4</ns1:Nonce>
<ns1:Created>2019-02-09T10:13:51.000Z</ns1:Created>
<ns1:Password>NGFjYTJiNzJmOWY2MzBmY2M2MjJkNjg1MDgyMWRjMzQxOGY1YTNjYQ==</ns1:Password>
</ns1:AuthHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:GetStockFileRequest>
<ns1:TestMode>true</ns1:TestMode>
<ns1:StockFileFormat>JSON</ns1:StockFileFormat>
<ns1:SortBy>StockCode</ns1:SortBy>
</ns1:GetStockFileRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
And I get an invalid credentials error. I've also been testing in SoupUI and the following request works:
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:api="http://www.beautyfort.com/api/">
<soapenv:Header>
<api:AuthHeader>
<api:Username>joetest</api:Username>
<api:Nonce>tJrsRlQt6i</api:Nonce>
<api:Created>2019-02-06T23:34:11.000Z</api:Created>
<api:Password>ZTBhMmE5OGY4YTNlZWIzZTE0ZTc2ZjZiZDBhM2RhMjJmNzAxNzYwZA==</api:Password>
</api:AuthHeader>
</soapenv:Header>
<soapenv:Body>
<api:GetStockFileRequest>
<api:TestMode>true</api:TestMode>
<api:StockFileFormat>JSON</api:StockFileFormat>
<!--Optional:-->
<api:FieldDelimiter>,</api:FieldDelimiter>
<!--Optional:-->
<api:StockFileFields>
<!--1 or more repetitions:-->
<api:StockFileField>StockCode</api:StockFileField>
<api:StockFileField>Category</api:StockFileField>
<api:StockFileField>Brand</api:StockFileField>
<api:StockFileField>Collection</api:StockFileField>
<api:StockFileField>Category</api:StockFileField>
</api:StockFileFields>
<api:SortBy>StockCode</api:SortBy>
</api:GetStockFileRequest>
</soapenv:Body>
</soapenv:Envelope>
Now the only differences I can see (apart from the optional fields) is the names of the namespace, and the use of the Xml tag at the top of the request. Both of these shouldn't matter right? I'd really appreciate your help on this as I've been scratching my head for ages.
Thank you in advance!
Your perfect just need to set UTC timezone and secret format like below:
base64 encoded(sha1(Nonce . Created . Secret))

How can I enable WS-RM (version 1.2) with NuSOAP client

Can enable I enable WS-RM (version 1.2) with NuSOAP client just like below? I tried this, but I cannot receive data from the API. Any ideas? Thanks.
$client = new nusoap_client($api_link, array('reliable' => 1.2 , 'useWSA' => TRUE) );
Full Code:
try {
include_once 'WebServiceSOAP/lib/nusoap.php';
$api_link = 'https://www.my-api.com/MYAPI.svc/SSL?wsdl';
$acode = '###';
$uname = '###';
$ttype = '###';
$ccode = '###';
$hpass = '###';
//setting xml request to api
$credentials = '<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/" xmlns:ezr="http://schemas.datacontract.org/2004/07/EzremitAPI.Entities">
<soapenv:Header/>
<soapenv:Body>
<tem:GetLocalRates>
<!--Optional:-->
<tem:credentials>
<!--Optional:-->
<ezr:AgentCode>'.$acode.'</ezr:AgentCode>
<!--Optional:-->
<ezr:HashedPassword>'.$hpass.'</ezr:HashedPassword>
<!--Optional:-->
<ezr:Username>'.$uname.'</ezr:Username>
</tem:credentials>
<!--Optional:-->
<tem:payincurcode>'.$ccode.'</tem:payincurcode>
<!--Optional:-->
<tem:transferType>'.$ttype.'</tem:transferType>
</tem:GetLocalRates>
</soapenv:Body>
</soapenv:Envelope>';
//creating soap object
$client = new nusoap_client($api_link, array('cache_wsdl' => WSDL_CACHE_NONE, 'soap_version' => SOAP_1_2) );
$client->soap_defencoding = 'UTF-8';
$soapaction = "http://tempuri.org/IRateAPI/GetLocalRates";
$xmlobjs = $client->send($credentials, $soapaction);
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
exit();
}
//print_r($client);
print_r($xmlobjs);
}
catch(Exception $e) {
echo $e->getMessage();
}
?>
I'm not very good at PHP and SOAP. Above code may have errors. Could you please check the code and give me your comments. I have made some amendments after searching Google.
Also, can I run this on PHP 5.4.42? When I run above code, I get below error now.
Constructor error
HTTP Error: Unsupported HTTP response status 415 Cannot process the message because the content type 'text/xml; charset=UTF-8' was not the expected type 'application/soap+xml; charset=utf-8'. (soapclient->response has contents of the response)
If anyone is looking for the answer to my above question, I found the solution with the help from #Marcel.
The answer to the question:
This code is wrong, don't use it.
$client = new nusoap_client($api_link, array('reliable' => 1.2 , 'useWSA' => TRUE) );
NuSoap client is outdated and not supporting to WS-RM. I had to use PHP inbuilt SOAP extension to get my project worked.
Full answer in here: SOAP Error in PHP: OperationFormatter encountered an invalid Message body
Thanks

Interacting with a soap API without WSDL in PHP

Recently got access to a soap API for a hotel management service. They have provided documentation which shows a basic example of a request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<Auth xmlns="http://xxxx/xxxxAPI">
<FromSystemId ID="1">CompanyName</FromSystemId>
<UserName>username</UserName>
<Password>password</Password>
</Auth>
</soapenv:Header>
<soapenv:Body>
<GetRegions Timestamp="2016-04-11" Version="1.0" Lang="en"
xmlns="http://xxxx/xxxxAPI">
<Country Code="GB" />
</GetRegions>
</soapenv:Body>
</soapenv:Envelope>
They have also provided a list of functions in their documentation and the parameters required for each of the functions. But i am abit confused on how to perform a request as i have never used a soap API before. They also haven't provided a WSDL, does this matter?
Anyway, here is how i thought to try and perform a request
$soapURL = "http://xxxx/xxxxAPI" ;
$soapParameters = Array('login' => "username", 'password' => "password") ;
$soapFunction = "getRegions";
$soapFunctionParameters = Array('countrycode' => 'GB');
$soapClient = new SoapClient($soapURL, $soapParameters);
$soapResult = $soapClient->__soapCall($soapFunction,
$soapFunctionParameters) ;
if(is_array($soapResult) && isset($soapResult['someFunctionResult'])) {
// Process result.
} else {
// Unexpected result
if(function_exists("debug_message")) {
debug_message("Unexpected soapResult for {$soapFunction}: ".print_r($soapResult, TRUE)) ;
}
}
Am i going about this the right way? i am unable to test this right now as i haven't received my authentication but wanted to make a start on it now.
Any help would be great.
Here is a small example.
$opts = array(
'location' => 'http://xxxx/xxxxAPI',
'uri' => 'urn:http://test-uri/'
);
$client = new SOAPClient(null, $opts);
$headerData = array(
'FromSystemId' => 'CompanyName',
'UserName' => 'username',
'Password' => 'password',
);
// Create Soap Header.
$header = new SOAPHeader('http://xxxx/xxxxAPI', 'Auth', $headerData);
// Set the Headers of Soap Client.
$client->__setSoapHeaders($header);
$result = $client->__soapCall('getRegions', array('GB'));
// $return = $client->__soapCall('getRegions', array(new SoapParam(new SoapVar('GB', XSD_STRING), 'countryCode')));
var_dump($result);
They also haven't provided a WSDL, does this matter?
To be able to add the HEADER attributes they must be mentioned in WSDL. If they not exist in WSDL they WILL NOT appear as attributes but rather <item><key/><value/></item> elements.
Tipp: If you know how the request has to be and you have no WSDL, then try to generate the HTTP header and XML body manually and execute the request with CURL or Guzzle.
Example with Guzzle:
$soapContent = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<Auth xmlns="http://xxxx/xxxxAPI">
<FromSystemId ID="1">CompanyName</FromSystemId>
<UserName>username</UserName>
<Password>password</Password>
</Auth>
</soapenv:Header>
<soapenv:Body>
<GetRegions Timestamp="2016-04-11" Version="1.0" Lang="en"
xmlns="http://xxxx/xxxxAPI">
<Country Code="GB" />
</GetRegions>
</soapenv:Body>
</soapenv:Envelope>';
$client = new GuzzleHttp\Client([
'headers' => [ 'SOAPAction' => '"urn:http://xxxx/xxxxAPI/#getRegions"' ]
]);
$response = $client->post('http://xxxx/xxxxAPI',
['body' => $soapContent]
);
echo $response;

Five9's API: How to pull reports using SOAP API and Basic Authentication

We are trying to access data from Five9's server using there reporting API. We have written code below but are not getting any results. To me it looks like issue is with the Authentication to Five9's server. Please check help us understand how we can pull data for a specific campaign on regular interval of time and store it in out Data Warehouse.
<?php
$soapUser = "USERNAME"; // username
$soapPassword = "DEMOPASSWORD"; // password
$soap_options = array( 'login' => $soapUser, 'password' => $soapPassword );
$auth_details = base64_encode($soapUser.":".$soapPassword);
$client = new SoapClient("https://api.five9.com/wsadmin/v2/AdminWebService?wsdl", $soap_options);
$header = new SoapHeader("https://api.five9.com/wsadmin/v2/AdminWebService/getCallLogReport", "authentication", "Basic $auth_details");
//echo "Response:\n" . $client->__getLastResponse() . "\n";
$client->__setSoapHeaders($header);
$xml_data = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v2="http://service.admin.ws.five9.com/v2/AdminWebService/getCallLogReport">
<soapenv:Header/>
<soapenv:Body>
<v2:getCallLogReport>
<campaigns>Campaign1</campaigns>
</v2:getCallLogReport>
</soapenv:Body>
</soapenv:Envelope>';
echo $result = $client->getCallLogReport($xml_data, "https://api.five9.com/wsadmin/v2/AdminWebService?wsdl", "https://api.five9.com/wsadmin/v2/AdminWebService/getCallLogReport",0);
?>
Sample XML
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v2="http://service.admin.ws.five9.com/v2/">
<soapenv:Header/>
<soapenv:Body>
<v2:getCallLogReport>
<!--Optional:-->
<time>
<!--Optional:-->
<end>?</end>
<!--Optional:-->
<start>?</start>
</time>
<!--Optional:-->
<criteria>
<!--Optional:-->
<ANI>?</ANI>
<!--Zero or more repetitions:-->
<agents>?</agents>
<!--Zero or more repetitions:-->
<callTypes>?</callTypes>
<!--Zero or more repetitions:-->
<campaigns>?</campaigns>
<!--Optional:-->
<DNIS>?</DNIS>
<!--Zero or more repetitions:-->
<dispositions>?</dispositions>
<!--Zero or more repetitions:-->
<lists>?</lists>
<!--Zero or more repetitions:-->
<skillGroups>?</skillGroups>
</criteria>
</v2:getCallLogReport>
</soapenv:Body>
</soapenv:Envelope>
I know this is an old question, but we recently switched to using Five9 and I couldn't find any PHP examples to work with. The following illustrates how to connect using standard credentials, and execute the call list. I've included the entire selection criteria structure (commented out) for your reference. If you include a selection property, you must specify the corresponding criteria.
$soap = null;
$wsdl = "https://api.five9.com/wsadmin/v2/AdminWebService?wsdl";
$user = "yourloginid";
$pass = "yourpassword";
$soap_options = array("login" => $user, "password" => $pass);
$soap = new SoapClient($wsdl, $soap_options);
/* create the callLogReportCriteria data selection structure */
$arryParams['time'] = array("start" => "2013-05-05T00:00:01",
"end" => "2013-05-05T09:00:00");
$arryParams['criteria'] = array("callTypes" => array("INBOUND","OUTBOUND"));
/************ Entire Structure for selection criteria *************/
/*$arryParams['criteria'] = array("ANI" => "6178752803",
"Agents" => "",
"callTypes" => array("INBOUND","OUTBOUND"),
"campaigns" => "",
"dispositions" => "",
"Lists" => "",
"skillGroups" => ""
);*/
$result = $soap->getCallLogReport($arryParams);
if(isset($result->return->records)) {
/* you have records returned */
$objRecords = $result->return->records;
for($i=0 ; $i < sizeof($objRecords) ; $i++) {
/* do your processing */
printf("ANI: %s<br />", $objRecords[$i]->values->data[3]); //4th element has ANI
}
}
Certain lines of code could be combined, but for the sake of understandability I broke them out. You will also want to utilize a try/catch around the actual SOAP call for error handling.
Hopefully this will help shorten someone's learning curve. I know I would have loved to have had this a month ago!!
It looks like your problem is that your sending your base64 encoded username/password in the soap header. It actually needs to be included in the http header. My solution is in ruby but hopefully it can help you out.
soap_client = Savon.client(
endpoint: "https://api.five9.com/wsadmin/AdminWebService/",
namespace: "http://service.admin.ws.five9.com/",
headers: { "Authorization" => "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==" },
env_namespace: :soapenv,
namespace_identifier: :ser,
ssl_verify_mode: :none
)
message = {
"lookupCriteria" => {
"criteria" => {
"field" => "email_address",
"value" => "something#example.com"
}
}
}
response = soap_client.call(:getContactRecords, message: message)
p response.body
So your XML ends up looking like this.
SOAP request: https://api.five9.com/wsadmin/AdminWebService/
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==, SOAPAction: "getContactRecords",
Content-Type: text/xml;charset=UTF-8, Content-Length: 471
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ser="http://service.admin.ws.five9.com/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ser:getContactRecords>
<lookupCriteria>
<criteria>
<field>email_address</field>
<value>something#example.com</value>
</criteria>
</lookupCriteria>
</ser:getContactRecords>
</soapenv:Body>
</soapenv:Envelope>
HTTPI POST request to api.five9.com (httpclient)
SOAP response (status 200)
<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>
<env:Header></env:Header>
<env:Body>
<ns2:getContactRecordsResponse xmlns:ns2="http://service.admin.ws.five9.com/" xmlns:ns3="http://service.admin.ws.five9.com/v1/">
<return>
<fields>number1</fields>
<fields>email_address</fields>
<records>
<values>
<data>5555555555</data>
<data>something#example.com</data>
</values>
</records>
</return>
</ns2:getContactRecordsResponse>
</env:Body>
</env:Envelope>
#JesseQ great example! Helped me a ton. Here's how I set it up to run any Five9 report in their arsenal including ones you create yourself. For custom reports, you'll need to create a new folder/report and place it in the "Custom Reports" section on the Five9 web portal. Hope this helps.
MySQL Database Connection (dbConnect.php)
<?php
$mysqli = new mysqli("your db's IP address", "your db user", "your db password", "your db");
if ($mysqli->connect_error) {
die('Connect Error: (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error);
}
?>
Five9/MySQL Database Import
<?php
require_once("../include/dbConnect.php");
$startDate = new DateTime();
$endDate = new DateTime();
$startDate->setDate(2015, 07, 22);
$endDate->setDate(2015, 07, 22);
$five9 = "https://api.five9.com/wsadmin/v2/AdminWebService?wsdl";
$five9Credentials = array("login" => "your Five9 username", "password" => "your Five9 password");
$soap = new SoapClient($five9, $five9Credentials);
$runReportParam["criteria"]["time"] = array("start" => $startDate->format("Y-m-d\T00:00:00"), "end" => $endDate->format("Y-m-d\T23:59:59"));
$runReportParam["folderName"] = "My Custom Reports";
$runReportParam["reportName"] = "My First Report";
$runReportResult = $soap->runReport($runReportParam);
if(isset($runReportResult->return)){
$runReportData = $runReportResult->return;
$isReportRunningParam["identifier"] = $runReportData;
$isReportRunningParam["timeout"] = 10;
$isReportRunningResult = $soap->isReportRunning($isReportRunningParam);
if(empty($isReportRunningResult->return)){
$getReportResultParam["identifier"] = $runReportData;
$getReportResult = $soap->getReportResult($getReportResultParam);
if(isset($getReportResult->return->records)){
$getReportResultData = $getReportResult->return->records;
echo "[" . date("Y-m-d h:i:s") . "] " . $runReportData . "\n";
for($x = 0; $x < $xx = count($getReportResultData); $x++){
$query = "REPLACE INTO MyTable(
CallDate, CallTime, DNIS, Disposition, Zip, AreaCode, ANI)
VALUES (?,?,?,?,?,?,?)";
$result = $mysqli->prepare($query);
$result->bind_param("sssssss",
$getReportResultData[$x]->values->data[0],
$getReportResultData[$x]->values->data[1],
$getReportResultData[$x]->values->data[2],
$getReportResultData[$x]->values->data[3],
$getReportResultData[$x]->values->data[4],
$getReportResultData[$x]->values->data[5],
$getReportResultData[$x]->values->data[6]
);
$result->execute();
$result->store_result();
if ($result->error){
die('Connect Error: (' . $result->errno . ') ' . $result->error);
}
echo "[" . date("Y-m-d h:i:s") . "] " . $x . "\n";
}
} else {
echo "Error: " . $runReportData . " returned no data";
}
} else {
echo "Error: " . $runReportData . " exceeded the report runtime limit";
}
} else {
echo "Error: " . $runReportParam["reportName"] . " wasn't found";
}
$mysqli->close();
?>

Create this SOAP XML request with PHP's SOAP extension

I'm trying to recreate this XML request using PHP's SOAP extension and having trouble doing it:
<?xml version="1.0"?>
<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:ser="http://services.web.stormpost.skylist.com">
<soapenv:Header>
<authInfo xmlns:soap="http://skylist.com/services/SoapRequestProcessor" xsi:type="soap:authentication">
<!--You may enter the following 2 items in any order-->
<username xsi:type="xsd:string">****#example.com</username>
<password xsi:type="xsd:string">*******</password>
</authInfo>
</soapenv:Header>
<soapenv:Body>
<ser:doImportFromTemplate soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<impTempId xsi:type="xsd:int">7</impTempId>
<data xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="soapenc:string">
Joe|Doe|joe#example.com John|Doe|john#example.com </data>
</ser:doImportFromTemplate>
</soapenv:Body>
</soapenv:Envelope>
Here is my testing code so far:
// set connection params
$wsdl = 'http://api.stormpost.datranmedia.com/services/SoapRequestProcessor?wsdl';
$namespace = 'https://api.stormpost.datranmedia.com/services/SoapRequestProcessor';
$credentials = (object)array(
'username' => '****#example.com',
'password' => '*******'
);
$auth_values = new SoapVar($credentials, SOAP_ENC_OBJECT);
$header = new SoapHeader($namespace, "authInfo", $auth_values);
// set client, headers, and call function
$client = new SoapClient($wsdl, array('trace' => true));
$client->__setSoapHeaders(array($header));
$client->__soapCall("doImportFromTemplate", array(7, 'Joe|Doe|joe#example.com John|Doe|john#example.com'));
It doesn't seem to be implementing the authInfo node correctly with the xsi:type="soap:authentication" among other things. How should I change my code to output this XML? I'm having trouble finding good implementation examples.
I struggled with the php SOAP client myself a while ago, i didn't really got a full understanding but this worked for me:
$auth_values = array('username' => '****#example.com', 'password' => '*******');
$header = new SoapHeader($namespace, "authInfo", $auth_values, false);
// set client, headers, and call function
$client = new SoapClient($wsdl, array('trace' => true));
$client->__setSoapHeaders(array($header));

Categories