techdreams techdreams - 2 years ago 191
Ruby Question

fetch ItemId in Amazon Product Api using Rails Vacuum gem

I am integrating Amazon Product Api in my rails app. I am using the vacuum gem for this integration. There are two main pages. I am fetching the products through this code.

requestd =

aws_access_key_id: ENV["AWS_ACCESS_KEY_ID"],
aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
associate_tag: ENV['ASSOCIATE_TAG']

response = requestd.item_search(
query: {
'SearchIndex' => @category.search_index,
'Keywords' => @category.keyword,
'ResponseGroup' => "ItemAttributes,Images"

hashed_products = response.to_h

@products = []

hashed_products['ItemSearchResponse']['Items']['Item'].each do |item|
product = = item['ItemAttributes']['Title']
product.price = item['ItemAttributes']['ListPrice']['FormattedPrice'] if item['ItemAttributes']['ListPrice']
product.url = item['DetailPageURL']
product.feature = item['ItemAttributes']['Feature']
product.image_url = item['LargeImage']['URL'] if item['LargeImage'] = item['ItemLinks']['ItemLink'][5]['URL']
@products << product

It gives ten products with matching request. But when I want to go to the detail page of a product in my app and show its respective details in my app I need ItemId of that product as given in the vaccum docs.

response = request.item_lookup(
query: {
'ItemId' => '0679753354'

But I am not able to fetch this Id. When I write
in the response group I do not get that although that is an attribute that could be written in ResponseGroup as per the Amazon Docs. I need that ItemId for item loopup operation to be performed so that I get Reviews and other details respective to that product separately.

Answer Source

I'm not familiar with Ruby, but the approach should be the same for every programming language. The ItemId attribute you are looking for is called ASIN and you should be able to fetch it in the following way:

product.asin = item['ASIN']
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download