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){
return htmlspecialchars( str_replace("<", "\n<", $xml) );
}
//this mini class is used for SOAP extension to create headers
class OurCallerAuth {
public $DeveloperKey;
public $Password;
public function \__construct($key, $pass){
$this->DeveloperKey = $key;
$this->Password = $pass;
}
}
//setup for the api calls
//url to the wsdl describing service
$urlToWsdl = "https://api.channeladvisor.com/ChannelAdvisorAPI/v1/InventoryService.asmx?WSDL";
//namespace of the calls
$authNameSpace = "http://api.channeladvisor.com/webservices/";
//name of the tag in header, user key and password
$loginTag = "APICredentials";
$developerKey = "XXX";
$developerPass = "YYY";
try {
//create SOAP object that will let us send calls, we need to pass the url of the WSDL file
$client = new SoapClient($urlToWsdl, array("trace" => 1, "exception" => 0) );
//now we can get list of methods provided by the web service if we want to do some automated scripts, validation etc
print_r( $client->__getFunctions() );
//build developer authorization header
$auth = new OurCallerAuth($developerKey, $developerPass);
$header = new SoapHeader($authNameSpace, $loginTag, $auth, false);
//call API
$result = $client->__soapCall("Ping", array("Ping" => array()), NULL, $header);
//the request object and actual request XML
print_r( $header );
print_r( "\n\n\n".showNiceXML($client->__getLastRequest())."\n\n\n" );
//the result object and the actual XML that we got
print_r( $result );
print_r( "\n\n\n".showNiceXML($client->__getLastResponse())."\n\n\n" );
//$result = $client->__soapCall("Ping", array("Ping" => array()), NULL, $oHeader);
} catch (SOAPFault $e) {
echo "ERROR:".$f->faultstring."\n\n";
echo "Request :\n".showNiceXML( $client->__getLastRequest() )."\n\n";
echo "Response:\n".showNiceXML( $client->__getLastResponse() )."\n\n";
}
?>
</pre>