To access the Amazon product advertising API you're going to need to create a signed URL per each request, which you can then later work with. You'll need to have the 3 codes below before reading any further as without these you cannot sign the request and will be unable to access the API.

1. AssociateTag
2. AWSAccessKeyId
3. AWS Secret Key

You can find out more information about how to get the above here.

Once you've got the above codes, you're ready to create a signed URL and begin accessing Amazons vast product library. I've wrapped all the necessary code into a function for you, which you can find at the bottom of this page and for now the only parts you need to change are the Associate Tag, AWS Access Key ID and AWS Secret Key.

So go ahead, replace the below values with your access keys and associate tag.


define("AWS_ASSOCIATE_TAG", "000000000000000");
define("AWS_API_KEY", "000000000000000000");
define("AWS_API_SECRET_KEY", "000000000000000000000000000000000000");

Now that you've added your details to the function we can simply call this with the parameters below and generate a signed URL.


echo signURL(1, "Board Games", "Toys");

We're using the ItemSearch operation for this example to specify that we'd like to see Page 1, for the search query "Board Games", in the Amazon category of "Toys". More information on ItemSearch can be found here and you can view a full list of search indexes here (this is for the UK) .

## Source Code


/*
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

<?php

function signURL($page_number,$search_term, $category) { define("AWS_ASSOCIATE_TAG", "000000000000000"); define("AWS_API_KEY", "000000000000000000"); define("AWS_API_SECRET_KEY", "000000000000000000000000000000000000"); define("RESPONSE_GROUP", "Images,ItemAttributes,OfferFull,OfferSummary,SalesRank"); define("OPERATION", "ItemSearch"); // format string to be signed$url = "GET\necs.amazonaws.co.uk\n/onca/xml\n" .
"AWSAccessKeyId=" . AWS_API_KEY .
"&AssociateTag=" . AWS_ASSOCIATE_TAG .
"&ItemPage=". $page_number . "&Keywords=" . rawurlencode(ucwords(str_replace("-", " ",$search_term))) .
"&Operation=" . OPERATION .
"&ResponseGroup=" . str_replace(",", "%2C", RESPONSE_GROUP) .
"&SearchIndex=" . str_replace(",", "%2C", $category) . "&Service=AWSECommerceService" . "&Timestamp=" . rawurlencode(gmdate("Y-m-d\TH:i:s\Z")) . "&Version=2011-08-01";$signature = base64_encode(hash_hmac("sha256", $url, AWS_API_SECRET_KEY, True));$signature = str_replace("%7E", "~", rawurlencode($signature)); return str_replace("GET\necs.amazonaws.co.uk\n/onca/xml\n", "http://ecs.amazonaws.co.uk/onca/xml?",$url) . "&Signature=" . \$signature;

}

?>