Ping Examples

Code samples provided here are generated by our clients and their developers. ChannelAdvisor cannot provide code for API development purposes.

Our documentation is meant to be the final format to be delivered to our API.

If you want to see other developer's code to execute calls, make a request of them on the ChannelAdvisor Google Forum.

Raw XML

POST /ChannelAdvisorAPI/v1/CartService.asmx HTTP/1.1
Host: api.0002.dev.channeladvisor.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://api.channeladvisor.com/webservices/Ping"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <APICredentials xmlns="http://api.channeladvisor.com/webservices/">
      <DeveloperKey>string</DeveloperKey>
      <Password>string</Password>
    </APICredentials>
  </soap:Header>
  <soap:Body>
    <Ping xmlns="http://api.channeladvisor.com/webservices/" />
  </soap:Body>
</soap:Envelope>

C# .Net

CartService svc1 = new CartService();
APICredentials credentials = new APICredentials();
credentials.DeveloperKey = "developerkey";
credentials.Password = "password";
svc1.APICredentialsValue = credentials;
APIResultOfString result = svc1.Ping();
Console.WriteLine("Call Result Data:{0}", result.ResultData);

PHP with NuSoap Toolkit

<?php
// Pull in the NuSOAP code
require_once('nusoap.php');
// Create the client instance
$client = new soapclient('https://api.channeladvisor.com/ChannelAdvisorAPI/v1/inventoryService.asmx?WSDL', true );
// Check for an error
$err = $client->getError();
if ($err)
{      // Display the error      echo 'Constructor error' . $err . '';      // At this point, you know the call that follows will fail  }
$developerKey = 'developerKey';
$password = 'password';
$headers = '
        <APICredentials xmlns="http://api.channeladvisor.com/webservices/">
        <DeveloperKey>'.$developerKey.'</DeveloperKey>
        <Password>'.$password.'</Password>
        </APICredentials>
        ';
// Call the SOAP method
$result = $client->call('Ping', array(), false, false, $headers);
// Check for a fault
if ($client->fault)
       echo 'Fault';
    print_r($result);
    echo '';  }
else {
    // Check for errors
    $err = $client->getError();
    if ($err)
{          // Display the error          echo 'Error' . $err . '';      }
else
{          // Display the result          echo 'Result';

        print_r($result);
    echo '';      }
}
// Display the request and response
echo '<h2>Request</h2>';
echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2>';
echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';

// Display the debug messages
echo '<h2>Debug</h2>';
echo '<pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>'; ?>

Ruby with soap4r 1.5.5

-- install soap4r
gem install soap4r
-- create client
ruby wsdl2ruby --wsdl https://api.channeladvisor.com/ChannelAdvisorAPI/v1/CartService.asmx?WSDL --type client --force
-- this generates the following files:
CartServiceClient.rb
default.rb
defaultdriver.rb
defaultMappingRegistry.rb
-- Create a new test.rb file, with this Ruby code:
#!/usr/bin/env ruby
require 'rubygems'
require_gem 'soap4r'
require 'defaultDriver.rb'
require 'soap/header/simplehandler'
class ClientAuthHeaderHandler < SOAP::Header::SimpleHandler
 APICredentialsName = XSD::QName.new('http://api.channeladvisor.com/webservices/', 'APICredentials')
  DeveloperKeyName = XSD::QName.new('http://api.channeladvisor.com/webservices/', 'DeveloperKey')
  PasswordName = XSD::QName.new('http://api.channeladvisor.com/webservices/', 'Password')
  def initialize(userid, passwd)
    super(APICredentialsName)
    @userid = userid
    @passwd = passwd
  end
  def on_simple_outbound

{PasswordName => @passwd, DeveloperKeyName => @userid}
  end
end
endpoint_url = 'https://api.channeladvisor.com/ChannelAdvisorAPI/v1/orderService.asmx'
obj = CartServiceSoap.new(endpoint_url)
# run ruby with -d to see SOAP wiredumps.
obj.wiredump_dev = STDERR if $DEBUG
obj.headerhandler << ClientAuthHeaderHandler.new('developerKey', 'password')
puts obj.ping(nil)
-- run this using ruby -d test.rb

Python 2.5 with SUDS

url = "https://api.channeladvisor.com/ChannelAdvisorAPI/v1/InventoryService.asmx?WSDL"
channel_advisor_inventory = Client(url, location="https://api.channeladvisor.com/ChannelAdvisorAPI/v1/InventoryService.asmx")
#The extra location is required because CA is https
message = """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://api.channeladvisor.com/webservices/">
   <soapenv:Header\>
   <soapenv:Body>
      <web:Ping/>
   </soapenv:Body>
</soapenv:Envelope>"""
login = channel_advisor_inventory.factory.create('APICredentials')
login.DeveloperKey = 'DeveloperKey'
login.Password = 'Password'
result = channel_advisor_inventory.service.addPerson(message)

Java with Axis 1.4

//Thanks go to Neil Aggarwal from JAMM Consulting for providing this sample

//Create an authentication handler class:
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPMessage;
import org.apache.axis.*;
import org.apache.axis.handlers.BasicHandler;
import org.apache.axis.message.SOAPHeaderElement;
import org.apache.log4j.Logger;

public class AuthenticationHandler extends BasicHandler {
  public void invoke(MessageContext context) throws AxisFault {
    try {
      MessageContext smc = (MessageContext) context;
      SOAPMessage message = smc.getMessage();
      QName APICredentialsName = new QName("http://api.channeladvisor.com/webservices/","APICredentials");
      QName DeveloperKeyName = new QName("http://api.channeladvisor.com/webservices/","DeveloperKey");
      QName PasswordName = new QName("http://api.channeladvisor.com/webservices/", "Password");

      SOAPHeader header = message.getSOAPHeader();
      SOAPHeaderElement cred = new SOAPHeaderElement(APICredentialsName);
      SOAPHeaderElement key = new SOAPHeaderElement(DeveloperKeyName);
      key.setObjectValue("DevKey");
      SOAPHeaderElement pw = new SOAPHeaderElement(PasswordName);
      pw.setObjectValue("Pass");
      cred.addChildElement(key);
      cred.addChildElement(pw);
      header.appendChild(cred);
    } catch (Exception e) {
      throw new AxisFault("Error during authentication", e);
    }
  }
}

//Then, create the ping client:
import org.apache.axis.Handler;
import org.apache.axis.SimpleChain;
import org.apache.axis.SimpleTargetedChain;
import org.apache.axis.client.AxisClient;
import org.apache.axis.configuration.SimpleProvider;
import org.apache.axis.transport.http.HTTPSender;
import org.apache.axis.transport.http.HTTPTransport;

public class Ping {
  public static void main(String[] args)
  throws Exception {
    SimpleProvider provider = new SimpleProvider();
    Handler handler = new AuthenticationHandler();
    SimpleChain requestChain = new SimpleChain();
    requestChain.addHandler(handler);
    SimpleChain responseChain = new SimpleChain();
    Handler sender = new HTTPSender();
    Handler transport = new SimpleTargetedChain(requestChain, sender, responseChain);

    provider.deployTransport(HTTPTransport.DEFAULT_TRANSPORT_NAME,transport);

    AdminServiceLocator locator = new AdminServiceLocator();
    locator.setEngineConfiguration(provider);
    locator.setEngine(new AxisClient(provider));
    locator.getAdminServiceSoap().ping();
  }
}

Python

Note: First off, you should note we do make use of a very specific Python library, suds. In Ubuntu, you can install this library by issuing the following command through your terminal:
$ sudo apt-get install python-suds
______________________________________________________________________________
 
from suds.client import Client
import logging

# Set logging to DEBUG so we can see the SOAP messages.
logging.basicConfig(level = logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)

# Specify Login Information?php
$developer_key
api_key = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
api_password = 'xxxxxxx'

# Specify URLs
wsdl_url = 'https://api.channeladvisor.com/ChannelAdvisorAPI/v5/InventoryService.asmx?WSDL'
service_url = 'https://api.channeladvisor.com/ChannelAdvisorAPI/v5/InventoryService.asmx'

# Initialize client.
client = Client(wsdl_url, location = service_url)

# Pass login information
login = client.factory.create('APICredentials')
login.DeveloperKey = api_key
login.Password = api_password
client.set_options(soapheaders=login)

# Initiate request
result = client.service.Ping()

# Print the result to the screen.
print result

PHP (Version not Defined)

<?php
$developer_key = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
$password = 'xxxxxx';
$wsdl_url = 'https://api.channeladvisor.com/ChannelAdvisorAPI/v3/InventoryService.asmx?WSDL';
$api_url = 'http://api.channeladvisor.com/webservices/';
// Instantiate the client.
$client = new SoapClient($wsdl_url);
// Pass along login information
$soap_header = new SoapHeader(
	$api_url,
	'APICredentials',
	array(
		'DeveloperKey' => $developer_key,
		'Password' => $password
	)
);
$client->__setSoapHeaders($soap_header);
// Initiate the request.
$result = $client->Ping();
// Print the results.
print '<pre>';
var_export($result);
print '</pre>';