I have been trying to get a list of all current active products after a s**t load of research and practice I managed to get together a script which will list the information I require which is stock available and the sku. Now the issue I have is I have to manually input the ebay id from the website however what I need is to automatically pull out the list of active ebay listings.
Here is the script which will gather the information for a single product.
error_reporting(E_ALL);
ini_set('display_errors', '1');
// Load configuration file
$sandbox = false;
$compat_level = 753;
$api_endpoint = $sandbox ? 'https://api.sandbox.ebay.com/ws/api.dll' : 'https://api.ebay.com/ws/api.dll';
$dev_id = $sandbox ? " " : " ";
$app_id = $sandbox ? " " : " ";
$cert_id = $sandbox ? " " : " ";
$auth_token = $sandbox ? " " : " ";
$site_id = 3;
$call_name = 'GetItem';
// Create headers to send with CURL request.
$headers = array
(
'X-EBAY-API-COMPATIBILITY-LEVEL: ' . $compat_level,
'X-EBAY-API-DEV-NAME: ' . $dev_id,
'X-EBAY-API-APP-NAME: ' . $app_id,
'X-EBAY-API-CERT-NAME: ' . $cert_id,
'X-EBAY-API-CALL-NAME: ' . $call_name,
'X-EBAY-API-SITEID: ' . $site_id,
);
// Generate XML request
$xml_request = "<?xml version="1.0" encoding="utf-8" ?>
<".$call_name."Request xmlns="urn:ebay:apis:eBLBaseComponents">
<RequesterCredentials>
<eBayAuthToken>" . $auth_token . "</eBayAuthToken>
</RequesterCredentials>
<DetailLevel>ReturnAll</DetailLevel>
<IncludeItemSpecifics>true</IncludeItemSpecifics>
<IncludeWatchCount>true</IncludeWatchCount>
<ItemID>191744777908</ItemID>
</".$call_name."Request>";
// Send request to eBay and load response in $response
$connection = curl_init();
curl_setopt($connection, CURLOPT_URL, $api_endpoint);
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($connection, CURLOPT_HTTPHEADER, $headers);
curl_setopt($connection, CURLOPT_POST, 1);
curl_setopt($connection, CURLOPT_POSTFIELDS, $xml_request);
curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($connection);
curl_close($connection);
// Create DOM object and load eBay response
$dom = new DOMDocument();
$dom->loadXML($response);
// Parse data accordingly.
$ack = $dom->getElementsByTagName('Ack')->length > 0 ? $dom->getElementsByTagName('Ack')->item(0)->nodeValue : '';
$eBay_official_time = $dom->getElementsByTagName('Timestamp')->length > 0 ? $dom->getElementsByTagName('Timestamp')->item(0)->nodeValue : '';
//$current_price = $dom->getElementsByTagName('ConvertedCurrentPrice')->length > 0 ? $dom->getElementsByTagName('ConvertedCurrentPrice')->item(0)->nodeValue : '';
//$description = $dom->getElementsByTagName('Description')->length > 0 ? $dom->getElementsByTagName('Description')->item(0)->nodeValue : '';
$itemID = $dom->getElementsByTagName('ItemID')->length > 0 ? $dom->getElementsByTagName('ItemID')->item(0)->nodeValue : '';
$customLabel = $dom->getElementsByTagName('SKU')->length > 0 ? $dom->getElementsByTagName('SKU')->item(0)->nodeValue : '';
$quantity = $dom->getElementsByTagName('Quantity')->length > 0 ? $dom->getElementsByTagName('Quantity')->item(0)->nodeValue : '';
$quantitySold = $dom->getElementsByTagName('QuantitySold')->length > 0 ? $dom->getElementsByTagName('QuantitySold')->item(0)->nodeValue : '';
$quantityAvaliable = $quantity - $quantitySold;
echo "ItemID: ".$itemID."<br>";
echo "sku: ".$customLabel."<br>";
echo "quantity: ".$quantity."quantitySold: ".$quantitySold." quantityAvaliable:".$quantityAvaliable;
What I cant figure our is how I can automatically take the listings from my eBay store. rather than having to individually enter each item id.
2
Answers
You are using the Getitem API which pulls a single item, you need to change the call to GetMyeBaySelling
Note1: This is only a starter for you, this will get you page 1 of your items in your store you can make the 1 here a variable to loop through the pages
"<PageNumber>1</PageNumber>";
You might ask how are you supposed to know how many pages you have? The answer is you dont need to know, eBay will give you the number of pages when you download the first one. The node you will be looking for is
ActiveList->PaginationResult->TotalNumberOfPages
Then use something like this to loop through the pageswhile ($PageNumber < $TotalNumberOfPages) {
Note2: You also might want to change the code above back to a variable if you want to match
</".$call_name."Request>";
like you had before. But you will need to change$call_name = 'GetItem';
to$call_name = 'GetMyeBaySelling';
Note3: Your site id is
$site_id = 3;
, if you are in the USA you might want to change that to a 1Note4: You also might want to change the
$compat_level = 753;
to the latest version 951 trading api version pageNote5: Since it looks like you are just getting stated with the eBay API, I might as well tell you that you are using the Trading API, and if you decide to use a different API like the merchandising API you will need to change the end point, but the endpoint you have now is set correctly for getmyebayselling (endpoint docs are here)
This can be used to get hold of all your active listings on your eBay. To explain this is basically making a request to eBay in the form of the xml. The xml request will tell eBay what you are after, eBay will then respond with the appropriate information in this case the active listings on your eBay account. Your xml response is stored within the var $response.
It is explained here
http://developer.ebay.com/DevZone/XML/docs/Reference/eBay/GetMyeBaySelling.html