W
W
WEWMEGADUV2016-08-25 13:42:17
JavaScript
WEWMEGADUV, 2016-08-25 13:42:17

How to create correct signature for mws amazon?

var protocol = "https";
var method = "POST";
var host = "mws.amazonservices.com";
var uri = "/Products/2011-10-01";
var marketPlaceId = "ATVPDKIKX0DER";




function generateRequest(asin, action){
    var today = new Date();
    time = today.toISOString();
    var parameters = {
        // "ASINList.ASIN.1":asin,
        "Query":asin,
        "AWSAccessKeyId":AWSAccessKeyId,
        "Action": action,
        "MarketplaceId":marketPlaceId,
        "SellerId": SellerId,
        "SignatureMethod":"HmacSHA256",
        "SignatureVersion":"2",
        "Timestamp":time,
        "Version":"2011-10-01"
    };

    //Convert to Query
    parameters = $.param( parameters );

    //Signature
    var messageToEncrypt =  method+"\n"+host+"\n"+uri+"\n"+parameters;

    var sig = CryptoJS.HmacSHA256(messageToEncrypt, SecretKey);

    sig = sig.toString(CryptoJS.enc.Base64);

    sig = encodeURIComponent(sig);

    parameters = parameters+"&Signature="+sig;
    var mwsRequest = protocol+"://"+host+uri+"?"+parameters;

    return mwsRequest;
}


// var asaUrl = generateRequest('B01I94N9TC','GetMatchingProduct');
var asaUrl = generateRequest('B01I94N9TC','ListMatchingProducts');


$.ajax({
    url:asaUrl,
    method: "POST",
    success: function(data){
        console.log(data)
    }
});

gives an error
Check your AWS Secret Access Key and signing method. Consult the service documentation for details.

but if send to GetMatchingProduct it works fine

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question