[ic] IC/eBay API integration -> impending donation

Grant listbox at email.com
Sun Sep 14 14:18:10 EDT 2003

I'm working on setting up my IC store to work with the eBay API to list
items, relist items, get end of auction information, and leave feedback for
eBay auctions.  It's close to complete, but I need some help before it's
ready to go.  I started a thread (which I think is still pending moderator
approval) asking for help getting the parsexml UserTag to exist for a
restart without causing an error.  I've been trying to figure that out, and
it seems that the problem is the nested subs.  I know very little about
Perl, but the tag passes perl -cw when the all-encapsulating sub{} is
removed.  Are subs inside the all-encapsulating sub allowed in UserTags?
Here's my reorganized version of the parsexml tag:

Usertag parsexml hasEndTag
Usertag parsexml Interpolate 1
Usertag parsexml Routine <<EOR
sub {
        my ($xml)=@_;
        require XML::Parser;
        my @field=();
        my $tag="";
        my $result="";

        my $parser=new XML::Parser(ErrorContext=>2);

                End =>\&End_Handler,

#       $result.="--cleanup--<br>\n"; # for debugging
        my $cleanxml=cleanupxml($xml);
#       return $cleanxml; # Preliminary exit for debugging purposes

#       $result.="cleanxml=<br>\n".$cleanxml."<br>\n"; # for debugging
        my $parseresult=$parser->parse($cleanxml);

        my $fieldname="";

#       $result.=substr($cleanxml,1,8); # for debugging

        foreach $fieldname (@field) {
                next if $fieldname eq "";
                next if $fieldname eq "XMLDOC_WRAPPER";
        return $result;

        sub cleanupxml {
                my ($xmltoclean)=@_;
                my $cleanedxml="";
                my $returnxml="";
                my $start="";
                my $line="";
                my $x=substr($xmltoclean,1,6);
                if (index($xmltoclean,"\<\?xml")<0) {
                        $cleanedxml="<\?xml version=\"1.0\"
#			."\<temp\>".$x."\<\/temp\>" # for debugging
                } else {


                my @xmllines=split("\n",$cleanedxml);
                foreach $line (@xmllines) {
                        next if (($line eq "")||($line eq "\n")||($line eq
                        if ($start ne "") {
                        next if lc(substr($line,0,5)) ne "\<\?xml";


                if ($returnxml eq "") {
                        return $returnxml
                        ."\<\?xml version=\"1.0\"
                return $returnxml."\<\/XMLDOC_WRAPPER\>";

	sub Start_Handler {
                my $p=shift;
                my $el=shift;
                while (my $key=shift) {
                        my $val=shift;

	sub End_Handler {
                my $p=shift;
                my $el=shift;

	sub Default_Handler {
                my $p=shift;
                my $el=shift;

                if (($el eq "")||($tag eq "")) {
                if ($tag eq "XMLDOC_WRAPPER") {
                push @field,$tag;$tag="";


I had to change this line:

next if (($line eq "")||($line eq "\n")||($line eq "\r")||($line eq "\s"));

to this:

next if (($line eq "")||($line eq "\n")||($line eq "\r"));

to keep perl -cw from complaining about an unrecognized escape.

Lastly, I can't seem to get the UserTags I have for the eBay API functions
to accept variables like this: [ebay_additem var1="myvar" var2="alsomyvar"]
.  The only way I can get it to work is to hard-code the variables into the
UserTag and call it like this: [ebay_additem] .  Here are the basics of the
ebay_additem UserTag:

Usertag ebay_additem Order sku category price title uuid
Usertag ebay_additem Routine <<EOR
use HTTP::Request::Common;
use LWP::UserAgent;
sub {
    my ($sku,$category,$price,$title,$uuid) = @_;

    my $ua = new LWP::UserAgent(
		timeout => 30,
		agent => 'ebay_additem',

    my $res = $ua->request(POST 'https://api.sandbox.ebay.com/ws/api.dll',
            X_EBAY_API_SESSION_CERTIFICATE => 'edited',
		X_EBAY_API_DEV_NAME => 'edited',
		X_EBAY_API_APP_NAME => 'edited',
		X_EBAY_API_CERT_NAME => 'edited',
		X_EBAY_API_CALL_NAME => 'AddItem',
		Content_Type => 'text/xml',
            Content => 'edited',
		Content_Length => 'length($content)',
    die $res->message() unless $res->is_success();

    return $res->as_string();

Once I have this stuff solved I may have a couple more questions before the
deed is done, but hopefully I can finish it off on my own.  The project is
probably 75% done.  I hope to have it finished and posted by the end of this
coming week.

So, if anyone can help me with the three things I'm stuck on I'd greatly
appreciate it.  Here they are:

1. nested subs in a UserTag
2. "unrecognized escape" error
3. passing variables to a UserTag

- Grant

More information about the interchange-users mailing list