midwesternpolicy avatar image
1 Like"
midwesternpolicy asked ·

can I use this code for ebay php api complete sale

there is php code that allows me to enter my ebay appID and ebay username
to get started
could I use something like this


* AUTHOR: Michael Hawthornthwaite - Acid Computer Services ( *

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
$applicationID - Application key obtained when registered at
$certificateID - Certificate key obtained when registered at
$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);

//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

//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;

does every ebay api have a different

 $compatabilityLevel = 551;    // eBay API version





//show all errors - useful whilst developing

// these keys can be obtained by registering at

$compatabilityLevel = 551; // eBay API version

$devID = ''; // these prod keys are different from sandbox keys
$appID = '';
$certID = '';
//set the Server to use (Sandbox or Production)
$serverUrl = ''; // server URL different for prod and sandbox
//the token representing the eBay user to assign the call with
$userToken = '';

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.

0 Answers

· Write an Answer

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.