This is my first test with the eBay's API. I'm attaching the code I am using and it gives me the following error:
2016-02-13 11:10:22FailureUnsupported API call.The API call "GeteBayTime" is invalid or not supported in this release.2ErrorRequestError92117790382
Code:
$EndPoint='https://api.sandbox.ebay.com/ws/api.dll';
$header= array(
'Content-Type: text/xml',
'X-EBAY-API-COMPATIBILITY-LEVEL: 921',
'X-EBAY-API-DEV-NAME: ' . $devId,
'X-EBAY-API-APP-NAME: ' . $appId,
'X-EBAY-API-CERT-NAME: ' . $certId,
'X-EBAY-API-CALL-NAME: ' . 'GeteBayTime',
'X-EBAY-API-SITEID: ' . '101',
'X-EBAY-API-REQUEST-ENCODING:XML'
);
$xml='<?xml version="1.0" encoding="utf-8"?>
<GeteBayTimeRequest xmlns="urn:ebay:apis:eBLBaseComponents">
</GeteBayTimeRequest>';
$connection = curl_init();
curl_setopt($connection, CURLOPT_URL, $EndPoint);
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($connection, CURLOPT_HTTPHEADER, $header);
curl_setopt($connection, CURLOPT_POST, 1);
curl_setopt($connection, CURLOPT_POSTFIELDS, $xml);
curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($connection);
curl_close($connection);
echo $response;
Can you tell me where I'm wrong? Thanks
The name of the Trading operation is called GeteBayOfficalTime not GeteBayTime. Replacing GeteBayTime with GeteBayOfficalTime in your code will make it work. In addition because you are calling a Trading operation you will need to add your eBay auth token to the API request.
$devId = '<DEV ID>';
$appId = '<APP ID>';
$certId = '<CERT ID>';
$authToken = '<AUTH TOKEN>';
$endPoint = 'https://api.sandbox.ebay.com/ws/api.dll';
$header = [
'Content-Type: text/xml',
'X-EBAY-API-COMPATIBILITY-LEVEL:921',
"X-EBAY-API-DEV-NAME:$devId",
"X-EBAY-API-APP-NAME:$appId",
"X-EBAY-API-CERT-NAME:$certId",
'X-EBAY-API-CALL-NAME:GeteBayOfficialTime',
'X-EBAY-API-SITEID:101',
'X-EBAY-API-REQUEST-ENCODING:XML'
];
$xml = <<<XML
<?xml version="1.0" encoding="utf-8"?>
<GeteBayOfficialTimeRequest xmlns="urn:ebay:apis:eBLBaseComponents">
<RequesterCredentials xmlns="urn:ebay:apis:eBLBaseComponents">
<eBayAuthToken>$authToken</eBayAuthToken>
</RequesterCredentials>
</GeteBayOfficialTimeRequest>
XML;
$connection = curl_init();
curl_setopt($connection, CURLOPT_URL, $endPoint);
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($connection, CURLOPT_HTTPHEADER, $header);
curl_setopt($connection, CURLOPT_POST, 1);
curl_setopt($connection, CURLOPT_POSTFIELDS, $xml);
curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($connection);
curl_close($connection);
echo $response;
In case you're interested I have developed an SDK for PHP. The example below shows how to use the SDK to call GeteBayOfficalTime. There are more examples available
use \DTS\eBaySDK\Constants;
use \DTS\eBaySDK\Trading\Services;
use \DTS\eBaySDK\Trading\Types;
$service = new Services\TradingService([
'apiVersion' => 921
'siteId' => Constants\SiteIds::IT,
'sandbox' => true
]);
$request = new Types\GeteBayOfficialTimeRequestType();
$request->RequesterCredentials = new Types\CustomSecurityHeaderType();
$request->RequesterCredentials->eBayAuthToken = $authToken;
$response = $service->geteBayOfficialTime($request);
if ($response->Ack !== 'Success') {
if (isset($response->Errors)) {
foreach ($response->Errors as $error) {
printf("Error: %s\n", $error->ShortMessage);
}
}
} else {
printf("The official eBay time is: %s\n", $response->Timestamp->format('H:i (\G\M\T) \o\n l jS F Y'));
}