question

pakeski avatar image
0 Likes"
pakeski asked ·

Problems connecting to eBay server

I've got this application that exchanges data with eBay Trading API using PHP/XML. It's been working fine for 3 weeks but since yesterday I wasn't able to connect anymore.

For simplicity, I've created a very simple script to test the communication, but I'm still stuck with the same problem.


//show all errors - useful whilst developing
error_reporting(E_ALL);

// these keys can be obtained by registering at http://developer.ebay.com

$production = true; // toggle to true if going against production
$compatabilityLevel = 833; // eBay API version
$siteID = 3; // siteID needed in request - US=0, UK=3, DE=77...

if ($production) {
$devID = '[devID]'; // these prod keys are different from sandbox keys
$appID = '[appID]';
$certID = '[certID]';

//set the Server to use (Sandbox or Production)
$serverUrl = 'https://api.ebay.com/ws/api.dll'; // server URL different for prod and sandbox
//the token representing the eBay user to assign the call with
$userToken = '[my_token]';
}

class eBaySession {

private $requestToken;
private $devID;
private $appID;
private $certID;
private $serverUrl;
private $compatLevel;
private $siteID;
private $verb;

/** __construct
Constructor to make a new instance of eBaySession with the details needed to make a call
Input: $userRequestToken - the authentication token fir the user making the call
$developerID - Developer key obtained when registered at http://developer.ebay.com
$applicationID - Application key obtained when registered at http://developer.ebay.com
$certificateID - Certificate key obtained when registered at http://developer.ebay.com
$useTestServer - Boolean, if true then Sandbox server is used, otherwise production server is used
$compatabilityLevel - API version this is compatable with
$siteToUseID - the Id of the eBay site to associate the call iwht (0 = US, 2 = Canada, 3 = UK, ...)
$callName - The name of the call being made (e.g. 'GeteBayOfficialTime')
Output: Response string returned by the server
*/
public function __construct($userRequestToken, $developerID, $applicationID, $certificateID, $serverUrl, $compatabilityLevel, $siteToUseID, $callName) {
$this->requestToken = $userRequestToken;
$this->devID = $developerID;
$this->appID = $applicationID;
$this->certID = $certificateID;
$this->compatLevel = $compatabilityLevel;
$this->siteID = $siteToUseID;
$this->verb = $callName;
$this->serverUrl = $serverUrl;
}

/** sendHttpRequest
Sends a HTTP request to the server for this session
Input: $requestBody
Output: The HTTP Response as a String
*/
public function sendHttpRequest($requestBody) {
//build eBay headers using variables passed via constructor
$headers = $this->buildEbayHeaders();

//initialise a CURL session
$connection = curl_init();
//set the server we are using (could be Sandbox or Production server)
curl_setopt($connection, CURLOPT_URL, $this->serverUrl);

//stop CURL from verifying the peer's certificate
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);

curl_setopt($connection, CURLOPT_VERBOSE, TRUE);
curl_setopt($connection, CURLOPT_TIMEOUT, 30);

//set the headers using the array of headers
curl_setopt($connection, CURLOPT_HTTPHEADER, $headers);

//set method as POST
curl_setopt($connection, CURLOPT_POST, 1);

//set the XML body of the request
curl_setopt($connection, CURLOPT_POSTFIELDS, $requestBody);

//set it to return the transfer as a string from curl_exec
curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);

//Send the Request
$response = curl_exec($connection);

//close the connection
curl_close($connection);

//return the response
return $response;
}

/** buildEbayHeaders
Generates an array of string to be used as the headers for the HTTP request to eBay
Output: String Array of Headers applicable for this call
*/
private function buildEbayHeaders() {
$headers = array(
//Regulates versioning of the XML interface for the API
'X-EBAY-API-COMPATIBILITY-LEVEL: ' . $this->compatLevel,
//set the keys
'X-EBAY-API-DEV-NAME: ' . $this->devID,
'X-EBAY-API-APP-NAME: ' . $this->appID,
'X-EBAY-API-CERT-NAME: ' . $this->certID,
//the name of the call we are requesting
'X-EBAY-API-CALL-NAME: ' . $this->verb,
//SiteID must also be set in the Request's XML
//SiteID = 0 (US) - UK = 3, Canada = 2, Australia = 15, ....
//SiteID Indicates the eBay site to associate the call with
'X-EBAY-API-SITEID: ' . $this->siteID,
);

return $headers;
}

}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>GeteBayOfficialTime</TITLE>
</HEAD>
<BODY>

<?php
//SiteID must also be set in the Request's XML
//SiteID = 0 (US) - UK = 3, Canada = 2, Australia = 15, ....
//SiteID Indicates the eBay site to associate the call with
$siteID = 3;
//the call being made:
$verb = 'GeteBayOfficialTime';
//Level / amount of data for the call to return (default = 0)
$detailLevel = 0;

///Build the request Xml string
$requestXmlBody = '<?xml version="1.0" encoding="utf-8" ?>';
$requestXmlBody .= '<GeteBayOfficialTimeRequest xmlns="urn:ebay:apis:eBLBaseComponents">';
$requestXmlBody .= "<RequesterCredentials><eBayAuthToken>$userToken</eBayAuthToken></RequesterCredentials>";
$requestXmlBody .= '</GeteBayOfficialTimeRequest>';

//Create a new eBay session with all details pulled in from included keys.php
$session = new eBaySession($userToken, $devID, $appID, $certID, $serverUrl, $compatabilityLevel, $siteID, $verb);
//send the request and get response
$responseXml = $session->sendHttpRequest($requestXmlBody);
if (stristr($responseXml, 'HTTP 404') || $responseXml == '')
die('<P>Error sending request');

//Xml string is parsed and creates a DOM Document object
$responseDoc = new DomDocument();
$responseDoc->loadXML($responseXml);


//get any error nodes
$errors = $responseDoc->getElementsByTagName('Errors');

//if there are error nodes
if ($errors->length > 0) {
echo '<P><B>eBay returned the following error(s):</B>';
//display each error
//Get error code, ShortMesaage and LongMessage
$code = $errors->item(0)->getElementsByTagName('ErrorCode');
$shortMsg = $errors->item(0)->getElementsByTagName('ShortMessage');
$longMsg = $errors->item(0)->getElementsByTagName('LongMessage');
//Display code and shortmessage
echo '<P>', $code->item(0)->nodeValue, ' : ', str_replace(">", "&gt;", str_replace("<", "&lt;", $shortMsg->item(0)->nodeValue));
//if there is a long message (ie ErrorLevel=1), display it
if (count($longMsg) > 0)
echo '<BR>', str_replace(">", "&gt;", str_replace("<", "&lt;", $longMsg->item(0)->nodeValue));
}
else { //no errors
//get the node containing the time and display its contents
$eBayTime = $responseDoc->getElementsByTagName('Timestamp');
echo '<P><B>The Official eBay Time is ', $eBayTime->item(0)->nodeValue, ' GMT</B>';
}
?>

</BODY>
</HTML>

This is the output:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>GeteBayOfficialTime</TITLE>
</HEAD>
<BODY>

* About to connect() to api.ebay.com port 443 (#0)
* Trying 66.135.211.100... * Timeout
* Trying 66.135.211.140... * Timeout
* Trying 66.211.179.150... * Timeout
* Trying 66.211.179.180... * Timeout
* Trying 66.135.211.101... * Timeout
* Trying 66.211.179.148... * Timeout
* connect() timed out!
* Closing connection #0
<P>Error sending request

Facts:

  1. I've tested this script in 2 completely different servers.
  2. I've made this same call on eBay Online Testing Tool, and it's working fine with my eBay dev keys.
  3. Nothing has changed with the code since the problem started to happen.

Anyone who has had similar issues? Any ideas?

Thanks!

ebay-trading-api
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

everything0161 avatar image
0 Likes"
everything0161 answered ·

seems to be working again now!

· Share
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

everything0161 avatar image
0 Likes"
everything0161 answered ·

Seem to be no able to use the API for the last four days - haven't changed anything

· Share
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

pakeski avatar image
0 Likes"
pakeski answered ·

UPDATE:

 

I have now tried to make a very basic call to eBay Trading Api endpoints using several diferent methods SOAP, XML / PHP, Python and all of them end in a time out error.

 

Anybody else experiencing the same problems?

Or could you confirm that you are connecting with no problems to eBay Trading API?

· Share
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.