Subject: | Time stamp bug in URI::Amazon::APA ver. 0.2 |
Date: | Tue, 25 Aug 2009 09:51:21 -0700 (PDT) |
To: | bug-URI-Amazon-APA [...] rt.cpan.org |
From: | Stuart Lemmen <cslemmen [...] yahoo.com> |
Dist. name: URI::Amazon::APA ver. 0.2
Perl ver.: This is perl, v5.8.8 built for MSWin32-x86-multi-thread
O/S: Win XP Pro 5.1
Greetings, I encountered several errors when attempting to make an "AWSECommerceService" request to Amazon Web Services that came down to this line in your URI::Amazon::APA package:
$q{Timestamp} ||= strftime( "%Y-%m-%dT%TZ", gmtime() ); # 2009-01-01T12:00:00Z
The first error was:
<?xml version="1.0"?><ItemLookupErrorResponse xmlns="http://ecs.amazonaws.com/doc/2009-01-01/"><Error><Code>InvalidParameterValue</Code><Message>Value 2009-08-25TZ for parameter Timestamp is invalid. Reason: Must be in ISO8601 format.</Message></Error><RequestID>a9b655f2-36b8-4ead-a49c-97d69efd069c</RequestID></ItemLookupErrorResponse>
I fixed that by creating a time stamp in in the correct format (and in the future, otherwise Amazon complained about it the request being too old!) by using the "DateTime" package's "iso8601" method.
To get this to work with your code I added a third key to the argument hash, "time_stamp" that I fill by creating a date with DateTime (in the future by one day - that may be overkill but it works) and then using the "iso8601" method. Here's my code for that:
my $today = new DateTime(year => get_current_year(),
month => localtime->mon() + 1,
day => localtime->mday() + 1, # Must be in the future!
hour => localtime->hour(),
minute => localtime->min(),
second => localtime->sec(),
time_zone => "America/Chicago");
And the call to your package's method:
$u->sign(key => 'my_access_key', secret => 'my_secret_key', time_stamp => $today->iso8601);
The line above in your code now looks lie:
$q{Timestamp} = $arg{time_stamp}; # 2009-01-01T12:00:00Z
I'm sure there's a more elegant/safer way of doing this but this works for me at the present - IE Amazon is happy and returning the right data and no errors :)
-Stuart Lemmen