Dashboard > PHP Community > ... > SCA with PHP > eBay SOAP Binding Documentation
Log In   View a printable version of the current page.
eBay SOAP Binding Documentation
Added by ibm_soa, last edited by Graham Charters on May 23, 2007  (view change)
Labels: 
(None)


The eBay SOAP Binding (binding.ebaysoap)

The eBay soap binding makes it easy to call eBay Web services through their SOAP API. It hides the complexities of the SOAP API and allows you to focus on calling the business methods and data. The SCA eBay SOAP binding hides this complexity by allowing you to specify the non-business information, such as security credentials and API version, as configuration parameters and then it makes sure these are correctly handled for each request. Below is an example showing how to call the eBay GetSearchResults operation:

<?php
// Get a proxy to the eBay soap API
$ebay = SCA::getService('eBaySvc.wsdl',
                        'ebaysoap',
                         array('config' => './config/ebay.ini'));

// Create the query input parameters
$request = $ebay->createDataObject('urn:ebay:apis:eBLBaseComponents',
                                   'GetSearchResultsRequestType');
$request->Version = 495;
$request->Query = 'ipod';
$request->createDataObject('Pagination');
$request->Pagination->EntriesPerPage = 10;

// Make the call
$results = $ebay->GetSearchResults($request);

// Iterate through the results
foreach ($results->SearchResultItemArray as $search_result_items) {
    foreach ($search_result_items as $search_result_item) {
        foreach ($search_result_item->Item as $name => $value)
            echo "<b>{$name}</b> $value<br/>";
    }
}
?>

The eBay ini file

The ini configuration file referred to in the getService() call looks as follows:

siteid = 1
version = 495
appid = "XXX"
routing = "default"
authtoken = XXX"
devid = "XXX"
authcert = "XXX"
location = "https://api.sandbox.ebay.com/wsapi"

Examples of the non-security values are shown. Please refer to the eBay developer documentation for the latest choice of values to use.

You will need to join the eBay Developers Program and request Access Keys in order to fill out the appid, authtoken, devid and authcert. You should also download the latest eBay WSDL file and ensure that the first parameter in the getService() points to it on your local file system. In the above example the WSDL is located in the same directory as the script making the call.

Calling eBay using a Reference

The eBay soap binding can also be used declaratively in a service reference. The following example shows an SCA Component which wrappers the eBay soap service to provide a simplified version of the GetSearchResults operation:

<?php

include 'SCA/SCA.php';


/**
 * Consumes eBay
 * @service
 *
 */
class eBayConsumer {

    /**
     * eBay service reference
     *
     * @reference
     * @binding.ebaysoap eBaySvc.wsdl
     *
     * @config ./config/ebay.ini
     */
    public $ebay;

    public function GetSearchResults() {
        // Create the body
        $request = $this->ebay->createDataObject('urn:ebay:apis:eBLBaseComponents', 'GetSearchResultsRequestType');
        $request->Version = 495;
        $request->Query = 'ipod';
        $request->createDataObject('Pagination');
        $request->Pagination->EntriesPerPage = 10;

        return $this->ebay->GetSearchResults($request);
    }
}

?>

Overriding the ini settings

You can override the setting in the ini file. This allows you to have a single file with the default settings which different scripts can then vary slightly. The example below shows how to override the location to point to the eBay production site.

$ebay = SCA::getService('eBaySvc.wsdl',
                        'ebaysoap',
                         array('config' => './config/ebay.ini',
                               'location' => 'https://api.ebay.com/wsapi));

and for a reference

/**
     * eBay service reference
     *
     * @reference
     * @binding.ebaysoap eBaySvc.wsdl
     *
     * @config ./config/ebay.ini
     * @location https://api.ebay.com/wsapi
     */
    public $ebay;

The convention used for the annotations is simply the ini property name prefixed with an '@' (e.g. devid can be specified using an annotation @devid).

Pre-requisites

The eBay SOAP API uses SSL (note how the location URLs begin with https), and therefore your PHP must be built with SSL support enabled.

Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.4.5 Build:#708 Apr 12, 2007) - Bug/feature request - Contact Administrators