Reputation: 81
I'm trying to use the amazon-ecs gem to access the Amazon Product Advertising API.
Right, now I'm running a very simple script to get it to run:
Amazon::Ecs.options = {
:AWS_access_key_id => 'my_access_key_id',
:AWS_secret_key => 'my_secret_key',
:associate_tag => 'my_associate_tag'
}
res = Amazon::Ecs.item_search('ruby', :search_index => 'All')
However, this returns a 400 Bad Request error. Any Ideas on what I could do?
Upvotes: 2
Views: 1063
Reputation: 350
I had a similar issue, here is how I resolved it:
First, I called Amazon::Ecs.methods
and saw there were debug
, and debug=
methods, Amazon::Ecs.debug
was set to false
so naturally I set that to true Amazon::Ecs.debug = true
, then tried the same search:
Amazon::Ecs.item_search('ruby')
# this time it gave the following output (secret keys masked by me)
irb(main):020:0> Amazon::Ecs.item_search('ruby')
Adding AWSAccessKeyId=*****************
Adding AssociateTag=*****************
Adding Keywords=ruby
Adding Operation=ItemSearch
Adding SearchIndex=Books
Adding Service=AWSECommerceService
Adding Timestamp=2015-11-13T20:25:04Z
Adding Version=2011-08-01
Request URL: http://ecs.amazonaws.com/onca/xml?AWSAccessKeyId=*****************&AssociateTag=*****************&Keywords=ruby&Operation=ItemSearch&SearchIndex=Books&Service=AWSECommerceService&Timestamp=2015-11-13T20%3A25%3A04Z&Version=2011-08-01&Signature=****************************%3D
Amazon::RequestError: HTTP Response: 400 Bad Request
from /Users/`whoami`/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/amazon-ecs-2.3.1/lib/amazon/ecs.rb:132:in `send_request'
from /Users/`whoami`/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/amazon-ecs-2.3.1/lib/amazon/ecs.rb:101:in `item_search'
from (irb):20
from /Users/`whoami`/.rbenv/versions/2.2.2/bin/irb:11:in `<main>'
Then, I copy/pasted the URL into a browser, which gave an XML response like this:
<ItemLookupErrorResponse xmlns="http://ecs.amazonaws.com/doc/2011-08-01/">
<Error>
<Code>AWS.InvalidAccount</Code>
<Message>
Your AccessKey Id is not registered for Product Advertising API. Please use the AccessKey Id obtained after registering at https://affiliate-program.amazon.com/gp/flex/advertising/api/sign-in.html
</Message>
</Error>
<RequestId>********-****-****-****-************</RequestId>
</ItemLookupErrorResponse>
In my particular case though, it turns out, I had everything setup properly, however I had just recently created a new access key, and it seemed to take a few minutes to accept my new credentials. Funny enough, as soon as I realized that may be the case, and tried again, it worked!
edit: In case it isn't obvious, the answer is in the message: "Your AccessKey Id is not registered for Product Advertising API. Please use the AccessKey Id obtained after registering at https://affiliate-program.amazon.com/gp/flex/advertising/api/sign-in.html"
Upvotes: 1