Reputation: 145
I'm not sure if I'm approaching this right. I run a trading card game website and signed up with eBay's Partner Network so I could link people to eBay to buy individual cards. Right now I'm able to load a link for each card that says something like "Buy [card name] on eBay" using their standard "Link Generator," but I'd also like to display the average price for the card so people know how much it is before they click the link. Something like "Buy [card name] for $9.99 + 2.99 shipping on eBay!"
I figured I would need to use eBay Partner Network's API to retrieve a listing of available auctions to access the price information, and so I signed up for their developer program. I've been able to get a listing of current auctions using the code below, but I can't figure out how to just simply display an average price or going for price for all current auctions. Right now it displays the prices for every auction, but I've seen other websites that show you what the cost + shipping is for a specific card. I'm not sure if this is even the way to approach this - I've never dealt with any of this before and their documentation isn't very beginner-friendly. ^_^;;
<script>
function _cb_findItemsByKeywords(root)
{
var items = root.findItemsByKeywordsResponse[0].searchResult[0].item || [];
var html = [];
html.push('<table width="100%" border="0" cellspacing="0" cellpadding="3"><tbody>');
for (var i = 0; i < items.length; ++i)
{
var item = items[i];
var title = item.title;
var pic = item.galleryURL;
var viewitem = item.viewItemURL;
var selling = item.sellingStatus[0].currentPrice[0]['__value__']
if (null != title && null != viewitem)
{
html.push('<tr>' +
'<td><a href="' + viewitem + '" target="_blank">' + title + '</a></td>' + '<td>' + selling + '</td></tr>');
}
}
html.push('</tbody></table>');
document.getElementById("results").innerHTML = html.join("");
}
</script>
Upvotes: 0
Views: 2111
Reputation: 121
this will be hard to do with just js. not sure what your website is running on but if its PHP you could just use a SDK like this: https://ebay-sdk.intradesys.com/ebay_api_sdk_online_generator and then call the API with the GetSellerList Call that will return you all eBay Item of a Seller including Price and Shipping
i have build you an example here: https://ebay-sdk.intradesys.com/s/9f61408e3afb633e50cdf1b20de6f466
the code will look somehow like this:
require_once 'EbatNs_Session.php';
require_once 'EbatNs_Logger.php';
require_once 'EbatNs_ServiceProxy.php';
require_once 'EbatNs_Session.php';
require_once 'EbatNs_DataConverter.php';
$session = new EbatNs_Session();
$session->setSiteId(0);
$session->setUseHttpCompression(1);
$session->setAppMode(0);
$session->setDevId(YOUR_DEV_ID_HERE);
$session->setAppId(YOUR_APP_ID_HERE);
$session->setCertId(YOUR_CERT_ID_HERE);
$session->setRequestToken(YOUR_TOKEN_HERE);
$session->setTokenUsePickupFile(false);
$session->setTokenMode(true);
require_once 'EbatNs_ServiceProxy.php';
$proxy = new EbatNs_ServiceProxy($session, 'EbatNs_DataConverterUtf8');
require_once 'GetSellerListRequestType.php';
$getsellerlistrequest = new GetSellerListRequestType();
$pagination = new PaginationType();
$getsellerlistrequest->setPagination($pagination);
$pagination->setEntriesPerPage("10");
$pagination->setPageNumber("1");
$getsellerlistrequest->setStartTimeFrom("2014-10-01 10:29:00");
$getsellerlistrequest->setStartTimeTo("2014-12-31 10:29:00");
$getsellerlistrequest->setUserID("thisbejimmy");
$getsellerlistrequest->addDetailLevel("ItemReturnDescription");
$getsellerlistrequest->setVersion("899");
$response = $proxy->GetSellerList($getsellerlistrequest);
and the API will tell you everything about the items, here an example (reduced the response to the important parts)
<Item>
<BuyItNowPrice currencyID="USD">0.0</BuyItNowPrice>
<ConvertedStartPrice currencyID="USD">24.95</ConvertedStartPrice>
<BidIncrement currencyID="USD">0.0</BidIncrement>
<ConvertedCurrentPrice currencyID="USD">24.95</ConvertedCurrentPrice>
<CurrentPrice currencyID="USD">24.95</CurrentPrice>
<MinimumToBid currencyID="USD">24.95</MinimumToBid>
<ShippingService>ShippingMethodStandard</ShippingService>
<ShippingServiceCost currencyID="USD">0.0</ShippingServiceCost>
<StartPrice currencyID="USD">24.95</StartPrice>
</Item>
like you can see you are getting alot of information regarding the price, current, start, next bid, buyout, shipping, etc.
Upvotes: 0