Wednesday, April 8, 2015

How to Automatically Leave Feedback for Buyers on eBay For Free Using Your Home Linux Server, Bash, Perl, and the Net::eBay module

Install Updates and Dependencies
$ sudo apt-get update && apt-get upgrade -y
$ sudo perl -MCPAN -e "install Net::eBay"

Three scripts were hacked together to make this work, the ebay-...pl scripts were came directly from the Net::eBay documentation page. Remember to put your ebay developer production keys in the same directory in a file called ebay.ini

Part I
Shell script that calls the perl scripts and finds all item numbers that we have not already left feedback for:
1:  #!/bin/bash  
2:  #  
3:  # Automatically leaves feedback for sold transactions when run from a cron job like so:  
4:  # 00 1 * * * /usr/bin/bash /path/to/this/script.sh > /dev/null 2&>1  
5:  EBAY_USER=USERNAME  
6:  LINUX_USERNAME=joe  
7:  FEEDBACK="\"Great Buyer, Fast Payment, Thanks! A+++++\""  
8:  for item in `/usr/bin/perl /home/$LINUX_USERNAME/code/ebay/ebay-get-my-sold.pl $EBAY_USER --sold | /bin/grep ItemID | /usr/bin/awk '{print $3;}' | /usr/bin/perl -pe "s/'(\d+)',?/\1/g" | /usr/bin/sort | /usr/bin/uniq` ;  
9:  do  
10:    if /bin/grep -Fxq "$item" /home/$LINUX_USERNAME/code/ebay/item_log  
11:    then<br>  
12:      /bin/echo &quot;$item already left feedback for this item&quot;  
13:    else  
14:      /home/$LINUX_USERNAME/code/ebay/ebay-leave-feedback.pl $item $FEEDBACK  
15:      /bin/echo $item &gt;&gt; /home/$LINUX_USERNAME/code/ebay/item_log  
16:    fi  
17:  done  


Part II
This script is supposed to print all your active or sold auctions in nicely formatted columns. I couldn't get it to dereference the correct array or scalar to work, so I just uncommented the datadumper line and grep through to find item id's. Perhaps the eBay API has modified their XML Schema and the Net::eBay module has yet to make the modifications.

Here's the link to the script: ebay-get-my-sold.pl
1:  #!/usr/bin/perl  
2:  use strict;  
3:  use warnings;  
4:  use Net::eBay;  
5:  use Data::Dumper;  
6:  my $eBay = new Net::eBay;  
7:  # use new eBay API  
8:  $eBay-&gt;setDefaults( { API =&gt; 2, debug =&gt; 0 } );  
9:  #my $seller = shift @ARGV || die "Usage: $0 seller-id";  
10:  my $kind = 'ActiveList';  
11:  my $status = 'active';  
12:  if( @ARGV &amp;&amp; $ARGV[0] eq '--sold' ) {  
13:   shift @ARGV;  
14:   $kind = 'SoldList';  
15:   $status = 'sold';  
16:  }  
17:  my $result = $eBay-&gt;submitRequest( "GetMyeBaySelling",  
18:                    {  
19:                    $kind =&gt; {  
20:                            Sort =&gt; 'EndTime',  
21:                            Pagination =&gt; {  
22:                                   EntriesPerPage =&gt; 199,  
23:                                   PageNumber =&gt; 1  
24:                                   }  
25:                           }  
26:                    }  
27:                   );  
28:  if( ref $result ) {  
29:   print "Result: " . Dumper( $result ) . "\n";  
30:   print "  Item   W B  Price Q  Title\n";  
31:   #7551933377  0 0  49.99 1 Siliconix Transistor tester IPT II 2 Monitor  
32:   my $arrayref;  
33:   if( $status eq 'active' ) {  
34:    $arrayref = $result-&gt;{$kind}-&gt;{ItemArray}-&gt;{Item};  
35:   } elsif( $status eq 'sold' ) {  
36:    $arrayref = $result-&gt;{$kind}-&gt;{OrderTransactionArray}-&gt;{Item};  
37:   }  
38:   foreach my $item (@$arrayref) {  
39:    print "$item-&gt;{ItemID} ";  
40:    print sprintf( "%3d ", $item-&gt;{WatchCount} || 0 );  
41:    print sprintf( "%2d ", $item-&gt;{SellingStatus}-&gt;{BidCount} || 0 );  
42:    print sprintf( "%7.2f ", $item-&gt;{SellingStatus}-&gt;{CurrentPrice}-&gt;{content} );  
43:    print "$item-&gt;{Quantity} $item-&gt;{Title} ";  
44:    print "\n";  
45:   }  
46:   print "$result-&gt;{SellingSummary}-&gt;{AuctionBidCount} bids\n";  
47:  } else {  
48:   print "Unparsed result: \n$result\n\n";  
49:  }  


Part III
This script actually leaves the feedback for an item, you call it like so: ./ebay-leave-feedback.pl ITEMNUMBER "Feedback to be left"

Get the Code from here ebay-leave-feedback.pl
1:  #!/usr/bin/perl  
2:  use strict;  
3:  use warnings;  
4:  use Net::eBay;  
5:  use Data::Dumper;  
6:  use DateTime::Precise;  
7:  use Getopt::Long;  
8:  my $usage = "Usage: $0 item-id{,item-id} feedback text\nNote:no spaces between item ids, ONLY COMMAS";  
9:  die $usage unless @ARGV;  
10:  my ($detail, $debug);  
11:  GetOptions(  
12:        "debug!" =&gt; \$debug,  
13:        );  
14:  my $eBay = new Net::eBay;  
15:  # use new eBay API  
16:  $eBay-&gt;setDefaults( { API =&gt; 2, debug =&gt; $debug } );  
17:  my $exitcode = 0;  
18:  my $items = shift @ARGV || die $usage;  
19:  foreach my $item ( split( /,/, $items ) ) {  
20:   die $usage unless $item =~ /^\d+$/;  
21:   my $text = join( ' ', @ARGV ) or die $usage;  
22:   my $result = $eBay-&gt;submitRequest( "GetItem",  
23:                     {  
24:                     ItemID =&gt; $item  
25:                     }  
26:                    );  
27:   if( ref $result ) {  
28:    if( $debug ) {  
29:     print "Result: " . Dumper( $result ) . "\n";  
30:    }  
31:    my $high_bidder = $result-&gt;{Item}-&gt;{SellingStatus}-&gt;{HighBidder}-&gt;{UserID};  
32:    if( $high_bidder ) {  
33:     my $fb = {  
34:          ItemID =&gt; $item,  
35:          TargetUser =&gt; $high_bidder,  
36:          CommentType =&gt; 'Positive',  
37:          CommentText =&gt; $text  
38:          };  
39:     my $fbresult = $eBay-&gt;submitRequest( "LeaveFeedback", $fb );  
40:     print "$item ($result-&gt;{Item}-&gt;{Title}): $fbresult-&gt;{Ack}\n";  
41:     unless( $fbresult-&gt;{Ack} eq 'Success' ) {  
42:      #print Dumper( $fbresult );  
43:      my $msg = $fbresult-&gt;{Errors}-&gt;{LongMessage};  
44:      print "Why: $msg\n";  
45:      if ( $msg =~ /Transaction ID is required/ ) {  
46:       print STDERR "Feedback for multiple quantity items is not supported.\n";  
47:       $exitcode = 0;  
48:      } elsif ( $msg =~ /or the feedback has been left already/ ) {  
49:       print STDERR "You already left feedback for this transaction.\n";  
50:       $exitcode = 1;  
51:      } else {  
52:       $exitcode = 1;  
53:      }  
54:     } else {  
55:      print STDERR "Success! $high_bidder $item &lt;-- data-blogger-escaped-code="" data-blogger-escaped-else="" data-blogger-escaped-exit="" data-blogger-escaped-exitcode="" data-blogger-escaped-found.="" data-blogger-escaped-item="" data-blogger-escaped-n="" data-blogger-escaped-not="" data-blogger-escaped-nparsed="" data-blogger-escaped-print="" data-blogger-escaped-result:="" data-blogger-escaped-result="" data-blogger-escaped-stderr="" data-blogger-escaped-tem="" data-blogger-escaped-text=""&gt;