How to get a JSON response for ItemLookup/Search using Amazon Product Advertising API
Asked Answered
M

2

37

I'm trying to get the details of Amazon product from its ASIN. The product API allows to do a Itemlookup with ASIN, but the return value is in XML.

I want to do this call for Itemlookup from client side, so would like to do a JSONP call, which I couldn't find.

I found some articles on the web to convert the XML to JSON format using XSLT stylesheet:

(a) https://bitbucket.org/basti/python-amazon-product-api/src/tip/examples/json-results.py

I tried using this python-amazon-product-api and this example, but I couldn't get a JSON return.

(b) http://www.kokogiak.com/gedankengang/2006/05/consuming-amazons-web-api-directly.html

The request I tried to send is:

http://xml-us.amznxslt.com/onca/xml?AWSAccessKeyId=[ACCESS KEY]&AssociateTag=[ASSOCIATE TAG]&ContentType=text%2Fjavascript&IdType=ASIN&ItemId=B008IEGS9W&Operation=ItemLookup&ResponseGroup=Images%2CItemAttributes&Service=AWSECommerceService&Style=http%3A%2F%2Fforums.delphiforums.com%2Fdelphidocsz%2Famazon%2Fjson.xsl&Timestamp=2012-09-04T06%3A40%3A11Z&Signature=AGOqXvVSeMp3YyVkT4mGNXVx0cFGG%2Bh%2FdAebevbbF9o%3D

Please help with getting a JSON format with Amazon product API.


The OP can run this style-sheet (input document not used) to determine his XSLT version.

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  exclude-result-prefixes="xsl msxsl">
<xsl:output method="html" indent="yes"/>

<xsl:template match="/">
  <html>
    <head><title>About your XSLT Processor</title></head> 
   <body>
     <ul>
       <li>xsl:version=<xsl:value-of select="system-property('xsl:version')" /></li>
       <li>xsl:vendor=<xsl:value-of select="system-property('xsl:vendor')" /></li>
       <li>xsl:vendor-url=<xsl:value-of select="system-property('xsl:vendor-url')" /></li>
       <li>xsl:product-name=<xsl:value-of select="system-property('xsl:product-name')" /></li>
       <li>xsl:product-version=<xsl:value-of select="system-property('xsl:product-version')" /></li>
       <li>xsl:is-schema-aware=<xsl:value-of select="system-property('xsl:is-schema-aware')" /></li>
       <li>xsl:supports-serialization=<xsl:value-of select="system-property('xsl:supports-serialization')" /></li>
       <li>xsl:supports-backwards-compatibility=<xsl:value-of select="system-property('xsl:supports-backwards-compatibility')" /></li>
       <li>msxsl:version=<xsl:value-of select="system-property('msxsl:version')" /></li>
     </ul>  
   </body>  
 </html>  
</xsl:template>
      
</xsl:stylesheet>
    
Morula answered 4/9, 2012 at 6:49 Comment(9)
Please supply a sample of the return value XML, and your particular required JSON format. It should then be possible to write an XSLT style-sheet to transform it into JSON. What version of XSLT can you use? 1.0? or 2.0?Smoothtongued
Please find the XML response at gist.github.com/3626354 . I would like to extract the product Title, details page link, the medium image of the product. I'm not sure of the version of the XSLT. How to find it out?Morula
Please run the stylesheet that I have included, and report results.Smoothtongued
Also, given the document you have linked, please list the JSON output that you would expect.Smoothtongued
And what if the Title contains a double quote (") character? Will you be satisfied with a simple solution that ignores this possiblity? Or do you want a robust solution that JSON encodes values (that is to say escapes the double quotes)? (Refer Max Shawabkeh's answer to stackoverflow.com/questions/2732409)Smoothtongued
+1 Any resolution to this question?Millar
The question still lacks what the desired JSON output format it. A simple Google search will provide hits to general XML->JSON conversion, but such solutions may be too general in this case. As for things like double quotes (assuming a custom JSON output is desired), you can use regex if using XSLT 2.0. If stuck with XSLT 1.0, see https://mcmap.net/q/426984/-xslt-1-0-string-replace-function.Dieldrin
@thomastinu, Please, edit the question and provide: 1) the XML document you have (from AWS); and 2) The exact JSON object you want to have.Slemmer
@Morula if the answer below worked for you, consider accepting the answer, and marking the question as resolved.Burlingame
B
6

Try either of these ::

  1. Amazon JSON API - This is a ruby webservice to pass through requests and translate the responses to JSON.
  2. Try any of these Javascript functions to convert the XML you already have into JSON :
    1. http://goessner.net/download/prj/jsonxml/
    2. http://davidwalsh.name/convert-xml-json
    3. http://www.fyneworks.com/jquery/xml-to-json/
    4. http://www.thomasfrank.se/xml_to_json.html

I've tried thomasfrank myself. Its easy and works well :)

Burlingame answered 4/4, 2013 at 17:12 Comment(0)
C
0

(disclosure) I’m Max and I’m a cofounder of Zinc (zinc.io). Our API produces a JSON response for both pricing and the product details page. Here’s a typical response for ASIN details: https://www.dropbox.com/s/peccdc1m2j34e0d/B018QPI98A.json?dl=0. If you're interested, see here: docs.zincapi.com

Cavorelievo answered 28/1, 2016 at 7:3 Comment(1)
Absolutely recommendedEndora

© 2022 - 2024 — McMap. All rights reserved.