Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get timestamp and Signature for Amazon Api

Tags:

api

amazon

I'm looking at reading Amazon Api . But not able to read the api as a url and getting the following message "invalid timestamp or signature". How to get values for both the fields.

like image 366
user3138111 Avatar asked Mar 11 '14 20:03

user3138111


People also ask

What is signature in REST API?

Getting Started. The OpenText Core Signature REST API enables you to create documents and send them for signature. Using the API, have all the functionality of the frontend and more. It is also possible to receive events from OpenText Core Signature when, for example, a document has been signed.


2 Answers

Try to follow the instructions and format here: http://docs.aws.amazon.com/AWSECommerceService/latest/DG/rest-signature.html

The signature is especially the difficult part as it has to be calculated and encoded. "Calculate an RFC 2104-compliant HMAC with the SHA256 hash algorithm using the string above with our "dummy" Secret Access Key: 1234567890. For more information about this step, see documentation and code samples for your programming language."

The timestamp is generally in this format: UTC time 2009-01-01T12:00:00Z

I would try this api signed requests helper: http://aws.amazon.com/code/Product-Advertising-API/2609

like image 59
amanda fouts Avatar answered Sep 30 '22 14:09

amanda fouts


Here I am the providing the code for signing the request .

$param = array();
$param['AWSAccessKeyId']   = USER_AWS_ACCESS_KEY_ID; 
$param['Action']           = 'GetFeedSubmissionList'; 
$param['SellerId']         = USER_MERCHANT_ID; 
$param['SignatureMethod']  = 'HmacSHA256'; 
$param['SignatureVersion'] = '2'; 
$param['Timestamp']        = gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time()); 
$param['Version']          = '2009-01-01'; 
$param['MarketplaceId']    = USER_MARKETPLACE_ID;  

$url = array();
foreach ($param as $key => $val){

 $key = str_replace("%7E", "~", rawurlencode($key));
 $val = str_replace("%7E", "~", rawurlencode($val));

 $url[] = "{$key}={$val}";
}

sort($url);

$arr   = implode('&', $url);

$sign  = 'GET' . "\n";
$sign .= str_replace("https://","",USER_AMAZON_URL) . "\n";
$sign .= '/' . "\n";
$sign .= $arr;

$signature = hash_hmac("sha256", $sign, USER_AWS_SECRET_ACCESS_KEY, true);
$signature = urlencode(base64_encode($signature));

$link  = USER_AMAZON_URL."?";
$link .= $arr . "&Signature=" . $signature;

$data = file_get_contents($link);
like image 36
TheVigilant Avatar answered Sep 30 '22 15:09

TheVigilant