Money-Code

Coding For Online Success

Finding BrowseNodes for Amazon API search (AWS)

| 0 comments

So, I’ve been hitting the Amazon sites real hard over the last month. With a combination of ReviewAZON, WPReviewSite and my own amazon store script, I’ve been picking niches and working on traffic. Today, I was looking at one of my good performing EPN store fronts, and I wanted to include Amazon products in there as well. The problem I was having was getting it targeted to the sub category. I knew the SearchIndex, but couldn’t figure out how to get the proper BrowseNode of the sub category. The solution is to do a BrowseNodeLookup call.

To do this, you first need to determine the main BrowseNode, basically the number related to the main category where your product is located in. To get this number, you may be able to see it in the URL, or use this matrix to get the proper BrowseNode based off of country:

http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/index.html?BrowseNodeIDs.html

Next, you need to query Amazon’s AWS and send this BrowseNode. You will receive a XML file containing all children related to this parent including name and BrowseNode.

Here is a basic function I wrote that will do a signed request for BrowseNodeLookup operation:

function find_browse_node_aws_signed_request($region, $params, $public_key, $private_key){
    $method     = "GET";
    $host               = "ecs.amazonaws.".$region;
    $uri                = "/onca/xml";
    $params["Service"]                  = "AWSECommerceService";
    $params["AWSAccessKeyId"]   = $public_key;
    $params["Timestamp"]                = gmdate("Y-m-d\TH:i:s\Z");
    $params["Version"]                  = "2009-03-31";
    ksort($params);
    $canonicalized_query = array();
    foreach ($params as $param=>$value){
        $param  = str_replace("%7E", "~", rawurlencode($param));
        $value  = str_replace("%7E", "~", rawurlencode($value));
                if($param == ‘ItemPage’ && $value == ‘x’){
                        $canonicalized_query[] = $param."=".$i;
                }else{
                $canonicalized_query[] = $param."=".$value;
                }
    }
    $canonicalized_query = implode("&", $canonicalized_query);
    $string_to_sign = $method."\n".$host."\n".$uri."\n".$canonicalized_query;
    $signature = base64_encode(hash_hmac(‘sha256’, $string_to_sign, $private_key, true));
    $signature = str_replace("%7E", "~", rawurlencode($signature));
    $request = "http://".$host.$uri."?".$canonicalized_query."&Signature=".$signature;
        $ch                     = curl_init();
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_URL, $request);
        $response       = curl_exec($ch);
        curl_close($ch);
        return $response;
}

To call the function you would do something like this:

$resp   = find_browse_node_aws_signed_request($country,
                        array("Operation"=>"BrowseNodeLookup",
                                        "Service"=>"AWSECommerceService",
                                        "BrowseNodeId"=>"111111111"
                                        ),
                        $pubKey,
                        $privKey);

$pubKey is your Associate Key ID (not your tracking ID) and the $privKey is your Secret AWS Key ID. You can do a var_dump($resp) to see the values of the returned array of values. After retrieving the BrowseNodeID, you can search within that category by passing ‘BrowseNode’ to your ItemSearch API call. Hope this helps!

Leave a Reply

Required fields are marked *.


CommentLuv badge

This site uses Akismet to reduce spam. Learn how your comment data is processed.