I have SoapUI working with this xml, but I need to consume that data on my server using php 5.3. I think I need to convert my $string into an array. the $xml = (array)simplexml_load_string($string); isn't throwing any errors, but the response from the call is NULL.
$string = '
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tran="http://www.cornerstoneondemand.com/Webservices/TranscriptAndTask">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-115E54B97689076253912">
<wsse:Username>me</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">word</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">dvhXLFiL4Aoi2KQ==</wsse:Nonce>
<wsu:Created>2016-10-19T15:26:02.539Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<tran:GetTranscriptAndTasks>
<tran:request>
<Request corpName="learning">
<User id="me">
<RequestTypes>
<Inbox/>
<Transcript inprogressOnly="false" pageNumber="1"/>
<Session pageNumber="1" upcomingOnly="true"/>
<Assigned assignedOnly="true"/>
<Approval approvalDateRequested="1967-08-13"/>
<Task pendingTasksOnly="true"/>
<SuggestedTraining pageNumber="1"/>
</RequestTypes>
</User>
</Request>
</tran:request>
</tran:GetTranscriptAndTasks>
</soapenv:Body>
</soapenv:Envelope>
';
$xml = (array)simplexml_load_string($string);
$soapClient = new SoapClient($wsdl, array('trace' => 1));
$response = $soapClient->GetTranscriptAndTasks($xml);
var_dump($response);
Any help is greatly appreciated!
Edit: I found https://github.com/sapankumarmohanty/lamp/blob/master/Crate-XML-2-Array that turns the xml into a nice array. But my result is still NULL...
I copied the WSDL here http://www.markforsyth.com/TranscriptAndTaskService.wsdl if it helps.
You can actually use xml code from SoapUI allmost direct.
Here are some code fragments from a code of mine:
Constructor for my class, that servs as a interface to a web service. wsdl is defined as a constant in the class:
public function __construct($username, $password) {
$this->client = new SoapClient(self::wsdl);
$this->client->__setSoapHeaders(self::securityHeader($username, $password));
}
Function in my class that return a security header used in the constructor:
private static function securityHeader($username, $password) {
$nsWSSE = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
$nsWSU = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";
$nonce = 'xxxxx';
$xml = '<nsWSSE:Security xmlns:nsWSSE="' . $nsWSSE . '" xmlns:nsWSU="' . $nsWSU . '">'
. '<nsWSSE:UsernameToken>'
. '<nsWSSE:Username>' . $username . '</nsWSSE:Username>'
. '<nsWSSE:Password>' . $password . '</nsWSSE:Password>'
. '<nsWSSE:Nonce>' . $nonce . '</nsWSSE:Nonce>'
. '<nsWSU:Created>' . gmdate('Y-m-d\TH:i:s\Z') . '</nsWSU:Created>'
. '</nsWSSE:UsernameToken>'
. '</nsWSSE:Security>';
$securityToken = new SoapVar($xml, XSD_ANYXML);
return new SoapHeader($nsWSSE, 'Security', $securityToken);
}
A function in my class, that makes a request to the WS-function "abc":
public function abc() {
$xml = ... paste your xml code from SoapUI here ...
$param = new SoapVar($xml, XSD_ANYXML);
return $this->client->abc($param);
}
Related
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))
I am trying to make a client request for a soap web service, and when I try to create the xml with simplexml_load_string it says this:
Error: Cannot create object
With no any other errors, so I can't figure it out what am I doing wrong, my code is bellow, I hope you can help me to solve this issue
<?php
$produccion = false; //Cambiar a verdadero por producction
$url = "http://ws.maxirest.com/wsclientes/wscli06896.php";
//print_r($_POST);
$posts = $_POST;
if ($produccion == false) {
$posts['nombre'] =
$posts['apellido'] =
$posts['direccion'] =
$posts['pisodto'] =
$posts['localidad'] =
$posts['partido'] =
$posts['provincia'] =
$posts['telefono'] =
$posts['celular'] =
"PRUEBA";
}
$Datos = "<cliente>
<nombre>".$posts['nombre']."</nombre>
<apellido>".$posts['apellido']."</apellido>
<calle>".$posts['direccion']."</calle>
<altura>".$posts['altura']."</altura>
<pisodto>".$posts['pisodto']."</pisodto>
<localidad>".$posts['localidad']."</localidad>
<partido>".$posts['partido']."</partido>
<provincia>".$posts['provincia']."</provincia>
<telefono>".$posts['telefono']."</telefono>
<celular>".$posts['celular']."</celular>
<num_tarjeta>".$posts['num_tarjeta']."</num_tarjeta>
</cliente>";
$myXMLData = '<?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:ws="http://ws.maxisistemas.com.ar">
<soapenv:Header/>
<soapenv:Body>
<ws:AltaSolicitud soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<cXml>'.$Datos.'</cXml>
<Clave>123ClubMilaMREST5</Clave>
</ws:AltaSolicitud>
</soapenv:Body>
</soapenv:Envelope>';
$xml=simplexml_load_string($myXMLData) or die("Error: Cannot create object"); //<-Here is the error
$client = new SoapClient($url);
$result1 = $client->AltaSolicitud($xml);
$result2 = $client->ConsultaPuntos($xml);
?>
I can't get an answer but
=> "ERROR. ACCESO NO PERMITIDO"
But with the right credentials and data you should be able to get the information you need with below class.
Simply set your data in the setData() function / call it first and then call AltoSolicitud() with Clave as parameter
class Request extends \SoapClient
{
public $Datos;
public function __construct(array $options = [], $wsdl = 'http://ws.maxirest.com/wsclientes/wscli06896.php?wsdl')
{
$options = [
'features' => 1,
];
parent::__construct($wsdl, $options);
}
/**
* #param string $Clave
* #return string
*/
public function AltaSolicitud()
{
$Data = $this->getData();
try {
return $this->__soapCall('AltaSolicitud', [
$Data
]);
} catch (\SoapFault $e) {
return ($e->getMessage());
}
}
public function setData($posts,$produccion = false)
{
if ( ! $produccion) {
$posts['nombre'] =
$posts['apellido'] =
$posts['direccion'] =
$posts['pisodto'] =
$posts['localidad'] =
$posts['partido'] =
$posts['provincia'] =
$posts['telefono'] =
$posts['celular'] =
"PRUEBA";
}
$Datos = "<cliente><nombre>".$posts['nombre']."</nombre>
<apellido>".$posts['apellido']."</apellido>
<calle>".$posts['direccion']."</calle>
<altura>".$posts['altura']."</altura>
<pisodto>".$posts['pisodto']."</pisodto>
<localidad>".$posts['localidad']."</localidad>
<partido>".$posts['partido']."</partido>
<provincia>".$posts['provincia']."</provincia>
<telefono>".$posts['telefono']."</telefono>
<celular>".$posts['celular']."</celular>
<num_tarjeta>".$posts['num_tarjeta']."</num_tarjeta></cliente>";
$Clave = '123ClubMilaMREST5';
$myXMLData = <<<XML
<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:ws="http://ws.maxisistemas.com.ar">
<soapenv:Header/>
<soapenv:Body>
<ws:AltaSolicitud soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<cXml xsi:type="xsd:string">' . str_replace(PHP_EOL,'',$Datos) . '</cXml>
<Clave xsi:type="xsd:string">' . $Clave . '</Clave>
</ws:AltaSolicitud>
</soapenv:Body>
</soapenv:Envelope>
XML;
$this->Datos = $myXMLData;
return $this;
}
/**
* #param string $Cod_Tarj
* #param string $Clave
* #return string
*/
public function ConsultaPuntos($Cod_Tarj, $Clave)
{
return $this->__soapCall('ConsultaPuntos', [$Cod_Tarj, $Clave]);
}
public function getData(){
return $this->Datos;
}
$request = (new Request)->setData($_POST,false)->AltaSolicitud();
var_dump($request);
#Ricardo
I was able to make your code work by adding "wsdl" to the url. After this change I did not see the error "Cannot create object".
$url = "http://ws.maxirest.com/wsclientes/wscli06896.php?wsdl";
I made some other minor changes, but I don't think they are important:
$xml = simplexml_load_string( $myXMLData ); //or die("Error: Cannot create object"); //<-Here is the error
$client = new SoapClient( $url , array('trace' => 1 ));
$result1 = $client->AltaSolicitud($xml);
echo "Response:\n" . $client->__getLastResponse() . "\n";
And the result was the same "ERROR. ACCESO NO PERMITIDO" already noted. To me it appears that the soap parameter <Clave>123ClubMilaMREST5</Clave>is incorrect or expired. I noticed this because the word is almost the same in Italian (chiave = clave = key). I assume this is an API key like many web services require?
SOAP 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/">
<SOAP-ENV:Body>
<ns1:AltaSolicitudResponse xmlns:ns1="http://ws.maxisistemas.com.ar">
<return xsi:type="xsd:string">ERROR. ACCESO NO PERMITIDO</return>
</ns1:AltaSolicitudResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I am trying to create this :
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<AccessKey xmlns="http://eatright/membership" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Value>67a4ef47-9ddf-471f-b6d0-0000c28d57d1</Value>
</AccessKey>
</s:Header>
<s:Body>
<WebUserLogin xmlns="http://eatright/membership">
<loginOrEmail>1083790</loginOrEmail>
<password>thomas</password>
</WebUserLogin>
</s:Body>
</s:Envelope>
I created this PHP code
class ChannelAdvisorAuth
{
public $AccessKey ;
public function __construct($key)
{
$this->AccessKey = $key;
}
}
$AccessKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$url = "http://ws.eatright.org/service/service.svc?wsdl";
$client = new SoapClient($url, array("trace" => 1, "exception" => 0));
$auth = new ChannelAdvisorAuth($AccessKey);
$header = new SoapHeader("AccessKey", "Value", $AccessKey, false);
$client->__setSoapHeaders($header);
$result = $client->ValidateAccessKey();
echo "REQUEST:\n" . $client->__getLastRequest() . "\n";
The output of the above PHP code is :
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://eatright/membership" xmlns:ns2="AccessKey">
<SOAP-ENV:Header>
<ns2:Value>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</ns2:Value>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:ValidateAccessKey/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
How to change the PHP code to output the XML as requested by web service provider?
How to replace the "SOAP-ENV" to "S"?
Is there is a way to remove the NS1 and NS2? and also adjust the whole format of the XML to meet the requirements? thanks
You don't need to worry about SOAP-ENV, ns1 or ns2 - they are just prefixes referring to the namespaces. As long as the full namespaces are correct, it's going to be alright.
I think the SOAP header should be made like this:
$access_key = new stdClass();
$access_key->Value = 'XXX';
$hdr = new SoapHeader('http://eatright/membership', 'AccessKey', $access_key);
$client->__setSoapHeaders($hdr);
I don't see a purpose of xmlns:i in the first example - there are no elements having XSI attributes.
I'm not sure what to do with the body. In your first example, there is a call to the WebUserLogin operation, while in your PHP code you are trying to call ValidateAccessKey.
Have you tried reading the WSDL file which is pointed by $url
Ok I found the problem and I will add it here in case someone looking for same issue.
$access_key = new stdClass();
$access_key->Value = 'xxxxxxxxxxxxxxxxxxx';
// Create the SoapClient instance
$url = "http://ws.eatright.org/service/service.svc?wsdl";
$client = new SoapClient($url, array("trace" => 1, "exception" => 0));
$hdr = new SoapHeader('http://eatright/membership', 'AccessKey', $access_key);
$client->__setSoapHeaders($hdr);
$soapParameters = array('loginOrEmail ' => $username, 'password' => $password);
$login = new stdClass();
$login->loginOrEmail='LoginID';
$login->password='Password';
$result = $client->WebUserLogin($login);
I want to create a WSS header to authentificate on secured web services.
I can do it using an ugly :
$auth = '
<wsse:Security SOAP-ENV:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsu:Timestamp wsu:Id="Timestamp-28" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsu:Created>' . $timestamp . '</wsu:Created>
<wsu:Expires>' . $timestampExpires . '</wsu:Expires>
</wsu:Timestamp>
<wsse:UsernameToken wsu:Id="UsernameToken-27" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>' . $user . '</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">' . $passdigest . '</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">' . $encodedNonce . '</wsse:Nonce>
<wsu:Created>' . $timestamp . '</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>';
I am now trying to do it cleaner, using SimpleXML.
But if I try to do a simple :
$xml = new SimpleXMLElement('<wsse:Security/>', 0, false, 'wsse');
I get :
warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]:
namespace error : Namespace prefix wsse on Security is not defined in
I think I miss something with the way to create namespaced xmls, can you give me some hints?
I found a way to solve my problem :
$root = new SimpleXMLElement('<root/>');
$security = $root->addChild('wsse:Security', 'test', 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd');
$root->registerXPathNamespace('wsse', 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd');
$auth = $root->xpath('/root/wsse:Security');
echo htmlentities($auth[0]->asXML());
Displays :
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">test</wsse:Security>
And also, there is a mistake in my XML, I put a SOAP-ENV:mustUnderstand="1" but I never define the SOAP-ENV namespace.
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();
?>