1

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 = Vacuum.new

    requestd.configure(
    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 = OpenStruct.new
      product.name = 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']
      product.link = item['ItemLinks']['ItemLink'][5]['URL']
      @products << product
    end

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 ItemId or ItemIds 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.

Dharmesh Rupani
  • 1,029
  • 2
  • 12
  • 22
techdreams
  • 5,371
  • 7
  • 42
  • 63
  • Can you, please, update your question with the response (in XML or JSON or any other form) you get from the ItemSearch operation? If you've gotten the response with ten items, each item should contain its id (an attribute called "ASIN"). – CyberMJ Feb 01 '16 at 05:22

1 Answers1

1

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']
CyberMJ
  • 865
  • 2
  • 12
  • 25