Search code examples
phpweb-servicessoap-clientebay-api

Connecting to eBay Trading API through SoapClient throws 'The web service eBayAPI is not properly configured or not found and is disabled' exception


I'm trying to connect to the ebay trading API and make a basic request using PHP's SoapClient class, but I'm having trouble. I've done hours of searching for and fiddling with examples, but I cannot get anything to work. So I wrote the following barebones code and I'm trying to get it working:

$token  = [token here];

$client = new SOAPClient('http://developer.ebay.com/webservices/latest/eBaySvc.wsdl', array('trace' => 1, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS));

$header = new SoapHeader('urn:ebay:apis:eBLBaseComponents', 'RequesterCredentials', new SoapVar(array('ebayAuthToken' => $token), SOAP_ENC_OBJECT), false);

$client->__setSoapHeaders(array($header));

$method = 'GeteBayOfficialTime';

$parameters = array(

);

try {
    $responseObj = $client->__soapCall($method, array($parameters));
}
catch (Exception $e)
{
    echo 'Exception caught. Here are the xml request & response:<br><br>';
    echo '$client->__getLastRequest():<br><pre><xmp>' . $client->__getLastRequest() . '</xmp></pre>';
    echo '$client->__getLastResponse():<br><pre><xmp>' . $client->__getLastResponse() . '</xmp></pre><br>';

    echo '<p>Exception trying to call ' . $method . '</p>';
    echo '$e->getMessage()';
    echo '<pre>' . $e->getMessage() . '</pre>';
}

The output of that is:

Exception caught. Here are the xml request & response:

$client->__getLastRequest():

<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:ebay:apis:eBLBaseComponents" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><SOAP-ENV:Header><xsd:RequesterCredentials><ebayAuthToken>[token was here]</ebayAuthToken></xsd:RequesterCredentials></SOAP-ENV:Header><SOAP-ENV:Body><ns1:GeteBayOfficialTimeRequest/></SOAP-ENV:Body></SOAP-ENV:Envelope>

$client->__getLastResponse():

<?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soapenv:Body> <soapenv:Fault> <faultcode>soapenv:Server.userException</faultcode> <faultstring>com.ebay.app.pres.service.hosting.WebServiceDisabledException: The web service eBayAPI is not properly configured or not found and is disabled.</faultstring> <detail/> </soapenv:Fault> </soapenv:Body> </soapenv:Envelope>


Exception trying to call GeteBayOfficialTime
$e->getMessage()

com.ebay.app.pres.service.hosting.WebServiceDisabledException: The web service eBayAPI is not properly configured or not found and is disabled.

Can anyone help me get this working? Part of the problem might be that I have no clue what should go in the first parameter of the SoapHeader function ("namespace").


Solution

  • After hours of hacking other people's examples and trying new stuff on my own, I finally was able to get this working. I'm posting the solution here in case it helps someone else:

    $token    = '';
    $appId    = '';
    $wsdl_url = 'ebaysvc.wsdl.xml'; // downloaded from http://developer.ebay.com/webservices/latest/eBaySvc.wsdl
    
    $apiCall = 'GetUser';
    
    $client = new SOAPClient($wsdl_url, array('trace' => 1, 'exceptions' => true, 'location' => 'https://api.sandbox.ebay.com/wsapi?callname=' . $apiCall . '&appid=' . $appId . '&siteid=0&version=821&routing=new'));
    
    $requesterCredentials = new stdClass();
    $requesterCredentials->eBayAuthToken = $token;
    
    $header = new SoapHeader('urn:ebay:apis:eBLBaseComponents', 'RequesterCredentials', $requesterCredentials);
    
    // the API call parameters
    $params = array(
        'Version' => 821,
        'DetailLevel' => 'ReturnSummary',
        'UserID' => ''
    );
    
    $responseObj = $client->__soapCall($apiCall, array($params), null, $header);  // make the API call
    

    Where the $token, $appId, and UserID are filled in with the appropriate values.

    A few notes:

    • Because exceptions are set to true, the SoapClient constructor call and all soapCall's should be inside of a try/catch block
    • The siteid parameter is set to 0, which indicates this is for the United States ebay website
    • The location URL should be changed from api.sandbox.ebay.com to api.ebay.com to use the production environment instead of the sandbox
    • I decided to download the WSDL file instead of using it remotely because it's very large (about 5MB) and slows down requests significantly

    I don't know why a simple example like this isn't available anywhere, but I sure wish it had been when I was trying to figure this out!