Amazon Product Ad APIs uses HMAC Authentication for user authentication.
HMAC is Keyed-Hash Message Authentication Code
and requires a secret key beforehand.
More can be read in the RFC2104.
The actual paper can be found here.
Assuming, you have the
- Amazon Access Key
- Amazon Secret Key
- Amazon Associates Tag
- Edit the
amazonKeys.sh
to add the above three information. - Source this file by
source amazonKeys.sh
. This will ensure that you have proper environmental variables. - If needed, edit the sign_paa.py file to set the appropriate hosts.
- Run the
sign_paa.py
file, by using this commandpython sign_paa.py
. Enter the SearchIndex and the Keywords. - The URL returned is the signed URL, that can be used to fetch the data using the Amazon Product Ad APIs.
- List of SearchIndices can be found here
There are many methods available in the sign_paa.py which can be used to sign any kind of requests.
Most notable of these are get_url_dict_cred(query_dict, access_key=None, secret_key=None, associate_tag=None, fmt_date=None)
Just pass a dictionary of the query parameters that need signing, along with credentials. The method would canonicalize the query params, sign them using the secret_key and return the complete url.
If the optional params are not passed, they are inferred from the environmental variables. If still not present, a ValueError
is thrown.
Testing done using py.test
. Install using pip install pytest
.
Test cases are present which are taken from the Amazon Docs here.