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”).
2
Answers
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:
Where the
$token
,$appId
, andUserID
are filled in with the appropriate values.A few notes:
siteid
parameter is set to0
, which indicates this is for the United States ebay websiteapi.sandbox.ebay.com
toapi.ebay.com
to use the production environment instead of the sandboxI 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!
Thank you for filing a support request.
I believe, you are looking for an authentication mechanism by which ebay users can authenticate your application to make API calls on their behalf. If this is the case, you have to use the Auth and Auth process, which is infact very simple.
The above process is explained in the following knowledge base article titled, Auth and Auth Quickstart: https://ebay.custhelp.com/app/answers/detail/a_id/1198
(If you search in the same knowledge base you can find sample auth and auth implementation for Java, PHP and .Net)
Here's more detailed information on the Auth and Auth process: http://developer.ebay.com/DevZone/guides/ebayfeatures/Basics/Tokens-MultipleUsers.html#GettingaTokenviaFetchToken
Here's an article on generating RuName: http://developer.ebay.com/DevZone/guides/ebayfeatures/Basics/Tokens-SettingUpApp.html#GenerateanRuNameforYourApplication
Please let me know if this helps or if you need further assistance.
Best Regards,
eBay Developer Support