Hack 87 Automatically Keep Track of Auctions You've Sold


Retrieve and store completed auction data without typing.

As explained in [Hack #65], it's vital for every seller to keep permanent, off-site records of every single auction he or she has sold.

This script, when run every day at the same time (as described in [Hack #17]), does it all:

require 'ebay.pl';

$today = &formatdate(time);
$yesterday = &formatdate(time - 86400);

my $page_number = 1;
while (1) {
    my $rsp = call_api({ Verb => 'GetSellerList',
                  DetailLevel => 8,
                       UserId => $user_id,
                  EndTimeFrom => $yesterday,
                    EndTimeTo => $today,
                   PageNumber => $page_number

    if ($rsp->{Errors}) {
      last PAGE;
    foreach (@{$rsp->{SellerList}{Item}}) {
      my %i = %$_;
      ($id, $enddate, $title, $currency, $price, $highbidder) =
             @i{qw/Id EndTime Title CurrencyId CurrentPrice HighBidder/};

      if (! -e "$localdir/$id") {       
        open (OUTFILE,">$localdir/$id");
          print OUTFILE "[Details]\n";
          print OUTFILE "enddate=$enddate\n";
          print OUTFILE "itemnumber=$id\n";
          print OUTFILE "title=$title\n";
          print OUTFILE "price=$currency$price\n";
          print OUTFILE "bidder=".$highbidder->{User}{UserId}."\n";
          print OUTFILE "bidderemail=".$highbidder->{User}{Email}."\n";
        close (OUTFILE);
    last PAGE unless $rsp->{SellerList}{HasMoreItems};

This script works similarly to the one in [Hack #85], but it retrieves a list of auctions by seller that have ended between the specified dates. Here are a few important things to note about this script:

  • Unlike the GetBidderList API call, which is limited to only 200 results, GetSellerList supports paging, and when used properly, will continue to retrieve results until you've got them all.

  • Since the DetailLevel input field (discussed in [Hack #84]) is set to 8, the GetSellerList retrieves all relevant information about an auction so we don't have to issue separate GetItem calls. This means we can retrieve the auction details for hundreds of listings with only one or two API calls.

  • The fields saved correspond to those listed in [Hack #65], with the exception of the shipping charge (see below) and any fields you'd normally enter manually (such as whether or not the bidder has yet paid).

  • If you've specified a fixed shipping charge in the listing or are using the Calculated Shipping option, you can retrieve this information with the GetItemShipping API call. Also of interest is GetShippingRates, a non-item-specific function that helps determine the shipping rates for different combinations of destination zip codes, package types, weights, and shipping services.