Skip to Main Content
Amazon Hacks
book

Amazon Hacks

by Paul Bausch
August 2003
Intermediate to advanced content levelIntermediate to advanced
304 pages
7h 33m
English
O'Reilly Media, Inc.
Content preview from Amazon Hacks

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

From ChatGPT to HackGPT: Meeting the Cybersecurity Threat of Generative AI

From ChatGPT to HackGPT: Meeting the Cybersecurity Threat of Generative AI

Karen Renaud, Merrill Warkentin, George Westerman
Incident Metrics in SRE

Incident Metrics in SRE

Stepan Davidovic

Publisher Resources

ISBN: 0596005423Supplemental ContentCatalog PageErrata