O'Reilly logo

Amazon Hacks by Paul Bausch

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Find a CD’s ASIN with the UPC

Instead of searching by Title or Artist, you can find an ASIN for a CD by using the UPC.

Almost every product has a UPC (Universal Price Code). Amazon doesn’t offer product searches by UPC through their main web site, but they do offer it for music products through their Web Services.

Following is a simple bit of JavaScript code that brings up a CD’s product detail page based on a UPC.

Tip

To run this script you’ll just need a developer’s token Section 6.4 and Internet Explorer for Windows.

The Code

Save this piece of HTML as a text file on your computer. Name it something appropriate (cd_asin.html will do nicely).

<html>

<head>

<title>Find a CD's ASIN</title>

<script language="JavaScript">

function getDetailPage(upc) {

    var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

    xmlhttp.Open("GET", "http://xml.amazon.com/onca/xml2?t=webservices-[RETURN]
20&dev-t=insert developer'stoken&UpcSearch="+upc+"&mode=music&type=lite[RETURN]
&f=xml", false);
    xmlhttp.Send(  );
    var response = xmlhttp.responseXML;
    if (response.selectSingleNode("/ProductInfo/ErrorMsg")) {
        alert(response.selectSingleNode("/ProductInfo/ErrorMsg").text);
    } else {
        var asin = response.selectSingleNode("/ProductInfo/Details/Asin")[RETURN]
.text;
        document.location = "http://amazon.com/o/ASIN/" + asin;
    }
}

</script>

</head>

<body>

<form>
    <input name="upc" type="text" size="25">
    <input type="button" value="Go" 
    onClick="getDetailPage(document.forms[0].upc.value);">
</form>

</body>

</html>

Running the Hack

Point your browser at the HTML page, cd_asin.html, enter a UPC code into the form, and click the Go button. If a match is found, you’ll be taken to that CD’s product detail page where you can jot down the ASIN.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required