Amazon Advertising API BrowseNodes


Amazon uses a hierarchy of nodes to organize its various items. Each node represents a collection of items, such as Harry Potter books, not the items themselves. Browse node IDs are positive integers that uniquely identify product collections, for example, Literature & Fiction: (17), Medicine: (13996), Mystery & Thrillers: (18), Nonfiction: (53), Outdoors & Nature: (290060). Amazon uses over 120,000 browse node IDs in the US locale alone.

The BrowseNodes tool automatically gets all the child BrowseNodes and their names. The program recursively traverses the BrowserNode hierarchy and returns all the BrowseNodes and their respective names. You can display the nodes on the console or save it to a CSV file. You can also include the library in your existing projects to process BrowseNodes.

Library Usage

The library is easy to use, and requires PHP and CURL installed on your system. The download includes a sample file with which you can immediately test the code. The sample file is shown below.

<?php
 
/* Example usage of the Amazon Product Advertising API */
include("amazon_api_class.php");
 
$public_key     = "YOUR-AMAZON-PUBLIC-KEY";
$private_key    = "YOUR-AMAZON-SECRET-KEY";
$region         = "com"; // or "CA" or "DE" etc.
 
$obj = new AmazonProductAPI($public_key, $private_key, $region);
 
/* Display the BrowseNodes to the console */
$obj->setMedia("display");
 
$obj->getBrowseNodes("1266092011");
 
?>

Before you begin to use the library, you need to enter your Amazon security credentials as shown above. Also in the ‘aws_signed_request.php’ file you will need to enter your Amazon Associate ID, as it is now mandatory. Find the following line in the file and add your Associated ID.

/* aws_signed_request.php */
.
.
$params["AssociateTag"]     = 'YOUR-ASSOCIATES-ID-HERE';
.

That is it. Now you are ready to get the BrowserNodes from Amazon. You can display the BrowserNodes on you console/browser or save it directly to a CSV file. For that you have to use the ‘setMedia’ method. Both example are shown below.

Display the BrowseNodes on the console

<?php
 
/* Example usage of the Amazon Product Advertising API */
include("amazon_api_class.php");
 
$public_key     = "YOUR-AMAZON-PUBLIC-KEY";
$private_key    = "YOUR-AMAZON-SECRET-KEY";
$region         = "com"; // or "CA" or "DE" etc.
 
$obj = new AmazonProductAPI($public_key, $private_key, $region);
 
/* Display the BrowseNodes to the console */
$obj->setMedia("display");
 
$obj->getBrowseNodes("1266092011");
 
?>

You enter the parent browsenode in the ‘getBrowseNodes’ method, after which the function recursively retrieves all the children nodes. To get started, you can find all the top browsenode values here, or you can get it from the Amazon link itself.

The output of the above is shown below. The output is indented so that you can visualize the hierarchy of the nodes.

Television & Video : AV Receivers & Amplifiers : 3213035011
Television & Video : Blu-ray Players & Recorders : 3213025011
      Blu-ray Players & Recorders : Blu-ray Recorders : 3213026011
      Blu-ray Players & Recorders : Blu-ray Players : 352697011
Television & Video : DVD Players & Recorders : 3213027011
      DVD Players & Recorders : DVD Players : 1036922
      DVD Players & Recorders : DVD Recorders : 1036920
Television & Video : DVD-VCR Combos : 886258
Television & Video : HD DVD Players : 352696011
Television & Video : Televisions : 172659
Television & Video : Home Theater Systems : 281056
.
.

The format of each line is given below.

Saving the BrowseNodes to a CSV

The following code shows how to save the browsenodes to a CSV file.

<?php
 
/* Example usage of the Amazon Product Advertising API */
include("amazon_api_class.php");
 
$public_key     = "YOUR-AMAZON-PUBLIC-KEY";
$private_key    = "YOUR-AMAZON-SECRET-KEY";
$region         = "com"; // or "CA" or "DE" etc.
 
$obj = new AmazonProductAPI($public_key, $private_key, $region);
 
/* Write the BrowseNodes to a CSV file */
$obj->setMedia("csv", "./nodes.csv");
 
$obj->getBrowseNodes("1266092011");
 
?>

The code saves all the browsenodes in a CSV file, after which you can use it with Excel or a simple text editor. A sample CSV ouput is shown below. The format is the same as the one given above.

"PlayStation 3","All Games","14210861"
"PlayStation 3","Action","14210761"
"Action","Fighting","14210981"
"Action","Military & Espionage","14210821"
"Action","Shooter","14210841"
"PlayStation 3","Adventure","14210851"
"PlayStation 3","Arcade","14210911"
"PlayStation 3","Board Games","14210921"

Changing Locales

Amazon being a world-wide venture the Product Advertising API operates in the following locales:
CA
CN
DE
ES
FR
IT
JP
UK
US

You can use different locale code to get the BrowseNodes for different regions. You set the locale parameter using the ‘$region’ variable; for example:

$region = "com"; // or "CA" or "DE" etc.

Getting the parent node details

You can also get information about a nodes parent node using the ‘getParentNode’ method.

<?php
 
/* Example usage of the Amazon Product Advertising API */
include("amazon_api_class.php");
 
$public_key     = "YOUR-AMAZON-PUBLIC-KEY";
$private_key    = "YOUR-AMAZON-SECRET-KEY";
$region         = "com"; // or "CA" or "DE" etc.
 
$obj = new AmazonProductAPI($public_key, $private_key, $region);
 
print_r($obj->getParentNode("14210821"));
 
?>

One other useful method you can use it ‘getNodeName’. This allows you to get the name of a given node id. This can be useful if you have a nodeid but need to gets it name.

<?php
 
/* Example usage of the Amazon Product Advertising API */
include("amazon_api_class.php");
 
$public_key     = "YOUR-AMAZON-PUBLIC-KEY";
$private_key    = "YOUR-AMAZON-SECRET-KEY";
$region         = "com"; // or "CA" or "DE" etc.
 
$obj = new AmazonProductAPI($public_key, $private_key, $region);
 
echo $obj->getNodeName("14210821");
 
?>

Note: Some categories contain hundreds to thousands of BrowserNodes, retreiving them can take some time and could trigger a PHP timeout error. To avoid this set PHP timeout to a large number as given below.

<?php
 
set_time_limit(10000); 
 
/* Example usage of the Amazon Product Advertising API */
include("amazon_api_class.php");
.
.
?>
Download code files
Downloads : 1950 / File size : 3.1 kB

This site is a digital habitat of Sameer Borate, a freelance web developer working in PHP, MySQL and WordPress. I also provide web scraping services, website design and development and integration of various Open Source API's. Contact me at metapix[at]gmail.com for any new project requirements and price quotes.

6 Responses

1

Shaun

January 24th, 2012 at 2:30 pm

I couldn’t get this to work, the code just repeats the first sub category within the node i am browsing, over and over and over and over again.

2

Ryan

September 6th, 2012 at 7:28 pm

It’s people like you who *SAVE* people like me hours and hours and hours of coding frustration

I’m doing market research for what kindle categories perform best, and my first step was to get a FULL breakdown of all of the book categories … as you know amazon only shows the breakdown of the current category / sub-category … but with this package I can see EVERYTHING with a simple node ID

Oh yea and you already had PRETTY output of the results built in with NESTED levels?! YOU ROCK!

Seriously I love you. This market research will be making me another six figures this year and your code and site made the beginning a breeze. Kudos. Keep up the AMAZING work!

-Ryan

3

found on yahoo

September 13th, 2012 at 3:09 am

I used to be recommended this web site by way of my cousin.

I am no longer certain whether this post is written through him as nobody else know such distinctive
about my problem. You are incredible! Thanks!

4

Gary

October 2nd, 2012 at 3:25 am

This is great…but I want to be able to just get the browsenode IDs for ONLY the next x levels down.

For example, I would like to get the IDs for the nodes one level down from ‘Books’ ‘Subjects’ node for Amazon.co.uk (id 1025612) as otherwise if I run the current code for that ID, I get 20,000+ nodes (ie everything beneath it) which I don’t want to sift through to try to work out which are the ones that are what I really want.

I’m sure there is a very simple way to do this, but as I’m not a coder, the tweaks I have tried don’t seem to work.

Many thanks in advance as having this additional functionality would be a massive help!

- Gary

5

Tyson

January 15th, 2013 at 11:39 am

I’m trying to get this to work for MP3′s, but the screenshots showing where to add values don’t appear to be the same in the downloadable file. I’m not experienced with programing, but I kind of understand a little bit of setting attributes.

Any Help would be appreciated.

I also tried my best to add the values in the correct places, but nothing happened, how to you run this to get it included in part of the WP site? I could place it, but didn’t know how to execute.

6

sani

May 26th, 2014 at 5:12 am

This is very helpful…

But i want to display all categories and subcategories list.Is there any browse node id for “All” category?if no,please give me some idea how to do it….

Thanks in advance…

Your thoughts