Dashboard > ChannelAdvisor Developer Network > ... > Inventory Service Examples > PHP Ping sample
Log In   View a printable version of the current page.
Added by Greg Smith, last edited by Greg Smith on Feb 14, 2008
Labels: 
(None)


Thanks to the CA team in our Ireland office!

<\!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>send calls</title>
</head>
<body>
<pre>
<?php
//for debug
function showNiceXML($xml){
&nbsp;&nbsp;&nbsp; return htmlspecialchars( str_replace("<", "\n<",&nbsp; $xml) );
}
//this mini class is used for SOAP extension to create headers
class OurCallerAuth {
&nbsp;&nbsp;&nbsp; public $DeveloperKey;
&nbsp;&nbsp;&nbsp; public $Password;
&nbsp;&nbsp;&nbsp; public function \__construct($key, $pass){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $this->DeveloperKey = $key;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $this->Password = $pass;
&nbsp;&nbsp;&nbsp; }
}
&nbsp;&nbsp;&nbsp; //setup for the api calls
&nbsp;&nbsp;&nbsp; //url to the wsdl describing service
&nbsp;&nbsp;&nbsp; $urlToWsdl&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = "https://api.channeladvisor.com/ChannelAdvisorAPI/v1/InventoryService.asmx?WSDL";
&nbsp;&nbsp;&nbsp; //namespace of the calls
&nbsp;&nbsp;&nbsp; $authNameSpace&nbsp; = "http://api.channeladvisor.com/webservices/";
&nbsp;&nbsp;&nbsp; //name of the tag in header, user key and password
&nbsp;&nbsp;&nbsp; $loginTag&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = "APICredentials";
&nbsp;&nbsp;&nbsp; $developerKey&nbsp;&nbsp; = "XXX";
&nbsp;&nbsp;&nbsp; $developerPass&nbsp; = "YYY";
&nbsp;&nbsp;&nbsp; try {
&nbsp;&nbsp;&nbsp;&nbsp; //create SOAP object that will let us send calls, we need to pass the url of the WSDL file
&nbsp;&nbsp;&nbsp;&nbsp; $client = new SoapClient($urlToWsdl, array("trace" => 1, "exception" => 0) );
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp; //now we can get list of methods provided by the web service if we want to do some automated scripts, validation etc
&nbsp;&nbsp;&nbsp;&nbsp; print_r( $client->__getFunctions() );
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp; //build developer authorization header
&nbsp;&nbsp;&nbsp;&nbsp; $auth&nbsp;&nbsp;&nbsp; = new OurCallerAuth($developerKey, $developerPass);
&nbsp;&nbsp;&nbsp;&nbsp; $header&nbsp; = new SoapHeader($authNameSpace, $loginTag, $auth, false);
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp; //call API
&nbsp;&nbsp;&nbsp;&nbsp; $result = $client->__soapCall("Ping", array("Ping" => array()), NULL, $header);
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp; //the request object and actual request XML
&nbsp;&nbsp;&nbsp;&nbsp; print_r( $header );
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print_r( "\n\n\n".showNiceXML($client->__getLastRequest())."\n\n\n" );
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //the result object and the actual XML that we got
&nbsp;&nbsp;&nbsp;&nbsp; print_r( $result );
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print_r( "\n\n\n".showNiceXML($client->__getLastResponse())."\n\n\n" );
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp; //$result = $client->__soapCall("Ping", array("Ping" => array()), NULL, $oHeader);
&nbsp;} catch (SOAPFault $e) {
&nbsp;&nbsp;&nbsp;&nbsp; echo "ERROR:".$f->faultstring."\n\n";
&nbsp;&nbsp;&nbsp;&nbsp; echo "Request :\n".showNiceXML( $client->__getLastRequest()&nbsp; )."\n\n";
&nbsp;&nbsp;&nbsp;&nbsp; echo "Response:\n".showNiceXML( $client->__getLastResponse() )."\n\n";
&nbsp;}
?>
</pre>&nbsp;
&nbsp;
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.1 Build:#806 May 06, 2007) - Bug/feature request - Contact Administrators