[ic] Donation: eBay UserTags

Grant listbox at email.com
Wed Nov 12 15:28:34 EST 2003


I'm still working on my IC/eBay integration and it's becoming more and
dependant on the specifics of my catalog and my particular usage of eBay.
The good news is the UserTags themselves are working 100% perfectly.  Here's
a quick description of each:

ebay_additem.tag:
It adds an item to eBay based on the parameters it is passed, and sets the
eBay item ID of the listed item to a scratch variable called
item_id_response.  The entire unparsed XML response from eBay is also saved
in a scratch variable called additem_log.

ebay_relistitem.tag:
It relists an eBay item based on the parameters it is passed, and sets the
eBay item ID of the relisted item to a scratch variable called
item_id_response.  The entire unparsed XML response from eBay is also saved
in a scratch variable called relistitem_log.

ebay_relistitem.tag:
It leaves positive feedback for an eBay member based on the parameters it is
passed, and sets the feedback response from eBay to a scratch variable
called feedback_status_response.  The entire unparsed XML response from eBay
is also saved in a scratch variable called leavefeedback_log.

ebay_getsellertransactions.tag
It gets all sold item information for an eBay member over the last 47 hours
based on the parameters it is passed, and sets all kinds of pertinent
information to scratch variables with each value separated by a space.  The
entire unparsed XML response from eBay is also saved in a scratch variable
called getsellertransactions_log.

Some data for each of these tags is pulled from a table called ebay_variable
which has fields "name" and "value".

I have used eBay for a long time, and these are the only eBay functions you
will need unless you would like some kind of special functionality.  In
order to use them you will need to follow the instructions here:
http://developer.ebay.com/DevProgram/membership/overview.asp .

I hope the wrapping doesn't screw the tags up, and if it does I'd be happy
to post them where they won't wrap if someone makes that available to me.
Also, I'm happy to answer any questions about all of this.  I'd rather they
be asked on the list so everyone can benefit from them, but if you want to
email me directly that's fine too.  A special thanks to everyone on the list
who helped me build these tags as well as Grant McLean (the author of
XML::Simple) who also helped a ton.

Enjoy!


# Interchange UserTag ebay_additem
#
# Copyright (C) 2003  Grant G.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
USA.

Usertag ebay_additem Order applicationdata category description duration
gallery galleryurl price quantity storecategory subtitletext title type
Usertag ebay_additem Routine <<EOR
use HTTP::Request::Common;
use LWP::UserAgent;
use XML::Simple;
$XML::Simple::PREFERRED_PARSER = 'XML::Parser';
sub {
	my ($applicationdata,$category,$description,$duration,$gallery,
$galleryurl,$price,$quantity,$storecategory,$subtitletext,$title,$type) =
@_;
	my $user_agent = new LWP::UserAgent(
		timeout => 30,
		agent => 'ebay_additem',
    	);
	$title =~ s:"":":g;
        my $requestuserid = tag_data('ebay_variable', 'value', 'user_id');
        my $requestpassword = tag_data('ebay_variable', 'value',
'password');
        my $dev_token = tag_data('ebay_variable', 'value', 'dev_token');
        my $app_token = tag_data('ebay_variable', 'value', 'app_token');
        my $cert_token = tag_data('ebay_variable', 'value', 'cert_token');
    	my $content = "<?xml version='1.0'
encoding='iso-8859-1'?><request><RequestUserId>$requestuserid</RequestUserId
><RequestPassword>$requestpassword</RequestPassword><ErrorLevel>1</ErrorLeve
l><DetailLevel>0</DetailLevel><SiteId>0</SiteId><Verb>AddItem</Verb><Applica
tionData>$applicationdata</ApplicationData><Category>$category</Category><Ch
eckoutInstructions>Your payment instructions will be emailed to you within
an hour of your eBay
purchase.</CheckoutInstructions><Country>us</Country><Currency>1</Currency><
Description><![CDATA[$description]]></Description><Duration>$duration</Durat
ion><Gallery>$gallery</Gallery><GalleryURL>$galleryurl</GalleryURL><Location
>www.TrippyStore.com</Location><MinimumBid>$price</MinimumBid><PaymentSeeDes
cription>1</PaymentSeeDescription><Quantity>$quantity</Quantity><Region>0</R
egion><StoreCategory>$storecategory</StoreCategory><SubtitleText>$subtitlete
xt</SubtitleText><Title>$title</Title><Type>$type</Type></request>";
    	my $request = $user_agent->request(POST tag_data('ebay_variable',
'value', 'request_url'),
		X_EBAY_API_COMPATIBILITY_LEVEL => '305',
                X_EBAY_API_SESSION_CERTIFICATE =>
"$dev_token;$app_token;$cert_token",
		X_EBAY_API_DEV_NAME => $dev_token,
		X_EBAY_API_APP_NAME => $app_token,
		X_EBAY_API_CERT_NAME => $cert_token,
		X_EBAY_API_CALL_NAME => 'AddItem',
		X_EBAY_API_SITEID => '0',
		X_EBAY_API_DETAIL_LEVEL => '0',
		Content_Type => 'text/xml',
                Content => $content,
    	);
    	my $xml_simple = XML::Simple->new(
    		KeyAttr    => [ ],
      		ForceArray => [ ],
    	);
    	my $response = $request->content;
    	my $eBay = $xml_simple->XMLin($response);
    	my $result = $eBay->{Item};
       	$Scratch->{item_id_response} = $result->{Id};
        $Scratch->{additem_log} = $response;
}
EOR


# Interchange UserTag ebay_relistitem
#
# Copyright (C) 2003  Grant G.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
USA.

Usertag ebay_relistitem Order itemid
Usertag ebay_relistitem Routine <<EOR
use HTTP::Request::Common;
use LWP::UserAgent;
use XML::Simple;
$XML::Simple::PREFERRED_PARSER = 'XML::Parser';
sub {
    	my ($itemid) = @_;
    	my $user_agent = new LWP::UserAgent(
		timeout => 30,
		agent => 'ebay_relistitem',
    	);
        my $requestuserid = tag_data('ebay_variable', 'value', 'user_id');
        my $requestpassword = tag_data('ebay_variable', 'value',
'password');
        my $dev_token = tag_data('ebay_variable', 'value', 'dev_token');
        my $app_token = tag_data('ebay_variable', 'value', 'app_token');
        my $cert_token = tag_data('ebay_variable', 'value', 'cert_token');
    	my $content = "<?xml version='1.0'
encoding='iso-8859-1'?><request><RequestUserId>$requestuserid</RequestUserId
><RequestPassword>$requestpassword</RequestPassword><ErrorLevel>1</ErrorLeve
l><DetailLevel>0</DetailLevel><Verb>RelistItem</Verb><SiteId>0</SiteId><Item
Id>$itemid</ItemId><RelistLink>1</RelistLink></request>";
    	my $request = $user_agent->request(POST tag_data('ebay_variable',
'value', 'request_url'),
		X_EBAY_API_COMPATIBILITY_LEVEL => '305',
                X_EBAY_API_SESSION_CERTIFICATE =>
"$dev_token;$app_token;$cert_token",
		X_EBAY_API_DEV_NAME => $dev_token,
		X_EBAY_API_APP_NAME => $app_token,
		X_EBAY_API_CERT_NAME => $cert_token,
		X_EBAY_API_CALL_NAME => 'RelistItem',
		X_EBAY_API_SITEID => '0',
		X_EBAY_API_DETAIL_LEVEL => '0',
		Content_Type => 'text/xml',
                Content => $content,
    	);
    	my $xml_simple = XML::Simple->new(
    		KeyAttr    => [ ],
      		ForceArray => [ ],
    	);
    	my $response = $request->content;
    	my $eBay = $xml_simple->XMLin($response);
    	my $result = $eBay->{Item};
       	$Scratch->{item_id_response} = $result->{Id};
        $Scratch->{relistitem_log} = $response;
}
EOR


# Interchange UserTag ebay_leavefeedback
#
# Copyright (C) 2003  Grant G.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
USA.

Usertag ebay_leavefeedback Order itemid userid transactionid
Usertag ebay_leavefeedback Routine <<EOR
use HTTP::Request::Common;
use LWP::UserAgent;
use XML::Simple;
$XML::Simple::PREFERRED_PARSER = 'XML::Parser';
sub {
	my ($itemid,$userid,$transactionid) = @_;
	my $user_agent = new LWP::UserAgent(
		timeout => 30,
		agent => 'ebay_leavefeedback',
    	);
        my $requestuserid = tag_data('ebay_variable', 'value', 'user_id');
        my $requestpassword = tag_data('ebay_variable', 'value',
'password');
        my $dev_token = tag_data('ebay_variable', 'value', 'dev_token');
        my $app_token = tag_data('ebay_variable', 'value', 'app_token');
        my $cert_token = tag_data('ebay_variable', 'value', 'cert_token');
    	my $content = "<?xml version='1.0'
encoding='iso-8859-1'?><request><RequestUserId>$requestuserid</RequestUserId
><RequestPassword>$requestpassword</RequestPassword><ErrorLevel>1</ErrorLeve
l><DetailLevel>0</DetailLevel><Verb>LeaveFeedback</Verb><SiteId>0</SiteId><I
temId>$itemid</ItemId><TargetUser>$userid</TargetUser><TransactionId>$transa
ctionid</TransactionId><CommentType>positive</CommentType><Comment>Smooth
transaction! Thanks for your business!</Comment></request>";
    	my $request = $user_agent->request(POST tag_data('ebay_variable',
'value', 'request_url'),
		X_EBAY_API_COMPATIBILITY_LEVEL => '305',
                X_EBAY_API_SESSION_CERTIFICATE =>
"$dev_token;$app_token;$cert_token",
		X_EBAY_API_DEV_NAME => $dev_token,
		X_EBAY_API_APP_NAME => $app_token,
		X_EBAY_API_CERT_NAME => $cert_token,
		X_EBAY_API_CALL_NAME => 'LeaveFeedback',
		X_EBAY_API_SITEID => '0',
		X_EBAY_API_DETAIL_LEVEL => '0',
		Content_Type => 'text/xml',
                Content => $content,
    	);
    	my $xml_simple = XML::Simple->new(
    		KeyAttr    => [ ],
      		ForceArray => [ ],
    	);
    	my $response = $request->content;
    	my $eBay = $xml_simple->XMLin($response);
    	my $result = $eBay->{LeaveFeedback};
       	$Scratch->{feedback_status_response} = $result->{Status};
        $Scratch->{leavefeedback_log} = $response;
}
EOR


# Interchange UserTag ebay_getsellertransactions
#
# Copyright (C) 2003  Grant G.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
USA.

Usertag ebay_getsellertransactions Order
Usertag ebay_getsellertransactions Routine <<EOR
use HTTP::Request::Common;
use LWP::UserAgent;
use XML::Simple;
$XML::Simple::PREFERRED_PARSER = 'XML::Parser';
sub {
	my $user_agent = new LWP::UserAgent(
		timeout => 30,
		agent => 'ebay_getsellertransactions',
	);
        my $requestuserid = tag_data('ebay_variable', 'value', 'user_id');
        my $requestpassword = tag_data('ebay_variable', 'value',
'password');
	my $lastmodifiedfrom = $Tag->time( { gmt => '1', adjust => '-47' },
'%Y-%m-%d %H:%M:%S' );
	my $lastmodifiedto = $Tag->time( { gmt => '1' }, '%Y-%m-%d %H:%M:%S' );
	my $dev_token = tag_data('ebay_variable', 'value', 'dev_token');
        my $app_token = tag_data('ebay_variable', 'value', 'app_token');
        my $cert_token = tag_data('ebay_variable', 'value', 'cert_token');
	my $content = "<?xml version='1.0'
encoding='iso-8859-1'?><request><RequestUserId>$requestuserid</RequestUserId
><RequestPassword>$requestpassword</RequestPassword><ErrorLevel>1</ErrorLeve
l><DetailLevel>4</DetailLevel><Verb>GetSellerTransactions</Verb><SiteId>0</S
iteId><LastModifiedFrom>$lastmodifiedfrom</LastModifiedFrom><LastModifiedTo>
$lastmodifiedto</LastModifiedTo></request>";
    	my $request = $user_agent->request(POST tag_data('ebay_variable',
'value', 'request_url'),
		X_EBAY_API_COMPATIBILITY_LEVEL => '305',
                X_EBAY_API_SESSION_CERTIFICATE =>
"$dev_token;$app_token;$cert_token",
		X_EBAY_API_DEV_NAME => $dev_token,
		X_EBAY_API_APP_NAME => $app_token,
		X_EBAY_API_CERT_NAME => $cert_token,
		X_EBAY_API_CALL_NAME => 'GetSellerTransactions',
		X_EBAY_API_SITEID => '0',
		X_EBAY_API_DETAIL_LEVEL => '4',
		Content_Type => 'text/xml',
                Content => $content,
    	);
    	my $xml_simple = XML::Simple->new(
      		KeyAttr    => [ ],
      		ForceArray => [ 'Transaction' ],
    	);
    	my $response = $request->content;
    	my $eBay = $xml_simple->XMLin($response);
    	my $result = $eBay->{GetSellerTransactionsResult};
    	my $transactions = $result->{Transactions}->{Transaction};
        $Scratch->{count_response} = $result->{Transactions}->{Count};
	foreach my $transaction (@$transactions) {
		$Scratch->{item_id_response} .= "$transaction->{ItemId} ";
		$Scratch->{transaction_id_response} .= "$transaction->{TransactionId} ";
       		$Scratch->{sku_response} .= "$transaction->{ApplicationData} ";
		$Scratch->{quantity_response} .= "$transaction->{QuantityPurchased} ";
		$Scratch->{price_response} .= "$transaction->{Price} ";
		$Scratch->{email_address_response} .=
"$transaction->{Buyer}->{User}->{Email} ";
		$Scratch->{user_id_response} .= "$transaction->{Buyer}->{User}->{UserId}
";
	}
        $Scratch->{getsellertransactions_log} = $response;
}
EOR



More information about the interchange-users mailing list