I’d like to make a soap call to the eBay api and finds products by keywords. With the help of eBay documentation and other online resources, I came up with this code:
$client = new SoapClient('http://developer.ebay.com/webservices/finding/latest/FindingService.wsdl');
$soap_headers = array(
new SoapHeader('X-EBAY-SOA-OPERATION-NAME', 'findItemsByKeywords'),
new SoapHeader('X-EBAY-SOA-SERVICE-VERSION', '1.3.0'),
new SoapHeader('X-EBAY-SOA-REQUEST-DATA-FORMAT', 'XML'),
new SoapHeader('X-EBAY-SOA-GLOBAL-ID', 'EBAY-US'),
new SoapHeader('X-EBAY-SOA-SECURITY-APPNAME', '<there would be the key>'),
);
$client->__setSoapHeaders($soap_headers);
// Call wsdl function
$result = $client->__soapCall("findItemsByKeywords", array("keywords" => "Potter"));
However, this code results in an error:
“Service operation is unknown,
500 Internal Server Error – SoapFault”
I tried changing the first line into this (don’t know why it should make a difference, but I saw it somewhere):
$client = new SoapClient(NULL, array(
"location" => 'http://svcs.sandbox.ebay.com/services/search/FindingService/v1',
'uri' => 'http://svcs.sandbox.ebay.com/services/search/FindingService/v1')
);
And now this result in this error: Missing SOA operation name header,
500 Internal Server Error – SoapFault
Does anybody know what causes these errors to occur and how to fix them?
Thank you, Mike!
2
Answers
The thing is, the service expects HTTP Headers (or query string parameters, apparently, by reading their guide a bit).
With
__setSoapHeaders
you are, well, setting SOAP Headers.Try this, for instance
The following code works.
As already mentioned, one of the issues is that you pass
X-EBAY-SOA-*
values as SOAP headers. The service expects them as HTTP headers:The second issue is that the
SoapClient
location
option is not specified. It should contain an URI to one of the service endpoints. Otherwise, the API returnsService operation is unknown
error.Finally, the
SoapClient
doesn’t put thekeywords
into Ebay’s namespace:As a result, the API returns an error:
Keywords value required.
. So I’ve specified the namespace for thekeywords
tag explicitly.Also note the use of different endpoint URIs for sandbox and for production.