Accessing Amazon MWS using Google Apps Script
I am somehow manage to write a code as per the documentation. But unfortunately it is not working. Below is the code, have a look, please let me know what im doing wrong or missing field. I have written this code by referring someone's code.
function test(){
var date = new Date();
var amz_date = date.toISOString(); //2018-05-01T20:40:50.940Z
var yearMonthDay= Utilities.formatDate(date, 'UTC', 'yyyyMMdd');
var hourMinuteSec = Utilities.formatDate(date, 'UTC', 'HHmmss');
var dateForStringToSign = yearMonthDay +'T'+hourMinuteSec+'Z'; //20180501T204050Z
var datestamp = yearMonthDay; // 20180501
var access_key = "xxxxxxxxxxxxx";
var secret_key = "xxxxxxxxxxxxx";
var method = 'POST';
var host = 'mws.amazonservices.com';
var endpoint = 'https://mws.amazonservices.com/Orders/2013-09-01';
var canonical_uri = '/Orders/2013-09-01';
var canonical_querystring = 'AWSAccessKeyId='+encodeURIComponent('xxxxxxxxxxxxx');
canonical_querystring += '&Action='+encodeURIComponent('GetOrder');
canonical_querystring += '&AmazonOrderId.Id.1='+encodeURIComponent('xxxxxxxxxxxxx');
canonical_querystring += '&MWSAuthToken='+encodeURIComponent('xxxxxxxxxxxxx');
canonical_querystring += '&SellerId='+encodeURIComponent('xxxxxxxxxxxxx');
canonical_querystring += '&SignatureMethod='+encodeURIComponent('HmacSHA256');
canonical_querystring += '&SignatureVersion='+encodeURIComponent('2');
canonical_querystring += '&Timestamp='+encodeURIComponent(amz_date);
canonical_querystring += '&Version='+encodeURIComponent('2013-09-01');
//To construct the finished canonical request, combine all the components
var finished_canonical= method + "n"+host+"n" +canonical_uri+ "n" + canonical_querystring;
//Calculate the Signature
var signature=getSignature(finished_canonical,secret_key);
//Add signature to querystring
canonical_querystring += '&Signature='+encodeURIComponent(signature);
Logger.log(canonical_querystring);
var request_url = endpoint + '?' + canonical_querystring;
var options = {
'method' : 'post',
'muteHttpExceptions':true,
'host': host,
}
var x = UrlFetchApp.fetch(request_url, options);
Logger.log(x);
}
Here is the Signature Generator function in GAS,
//Return Signatue (hash) from HmacSha256
function getSignature(message,secret){
var byteSignature = Utilities.computeHmacSha256Signature(message, secret);
// convert byte array to hex string
var signature = byteSignature.reduce(function(str,chr){
chr = (chr < 0 ? chr + 256 : chr).toString(16);
return str + (chr.length==1?'0':'') + chr;
},'');
return signature;
}
As you can see in the code, after generating the Signature, im appending it as a last parameter to the query string. Would that be a issue?
javascript xml amazon-web-services google-apps-script amazon-mws
add a comment |
I am somehow manage to write a code as per the documentation. But unfortunately it is not working. Below is the code, have a look, please let me know what im doing wrong or missing field. I have written this code by referring someone's code.
function test(){
var date = new Date();
var amz_date = date.toISOString(); //2018-05-01T20:40:50.940Z
var yearMonthDay= Utilities.formatDate(date, 'UTC', 'yyyyMMdd');
var hourMinuteSec = Utilities.formatDate(date, 'UTC', 'HHmmss');
var dateForStringToSign = yearMonthDay +'T'+hourMinuteSec+'Z'; //20180501T204050Z
var datestamp = yearMonthDay; // 20180501
var access_key = "xxxxxxxxxxxxx";
var secret_key = "xxxxxxxxxxxxx";
var method = 'POST';
var host = 'mws.amazonservices.com';
var endpoint = 'https://mws.amazonservices.com/Orders/2013-09-01';
var canonical_uri = '/Orders/2013-09-01';
var canonical_querystring = 'AWSAccessKeyId='+encodeURIComponent('xxxxxxxxxxxxx');
canonical_querystring += '&Action='+encodeURIComponent('GetOrder');
canonical_querystring += '&AmazonOrderId.Id.1='+encodeURIComponent('xxxxxxxxxxxxx');
canonical_querystring += '&MWSAuthToken='+encodeURIComponent('xxxxxxxxxxxxx');
canonical_querystring += '&SellerId='+encodeURIComponent('xxxxxxxxxxxxx');
canonical_querystring += '&SignatureMethod='+encodeURIComponent('HmacSHA256');
canonical_querystring += '&SignatureVersion='+encodeURIComponent('2');
canonical_querystring += '&Timestamp='+encodeURIComponent(amz_date);
canonical_querystring += '&Version='+encodeURIComponent('2013-09-01');
//To construct the finished canonical request, combine all the components
var finished_canonical= method + "n"+host+"n" +canonical_uri+ "n" + canonical_querystring;
//Calculate the Signature
var signature=getSignature(finished_canonical,secret_key);
//Add signature to querystring
canonical_querystring += '&Signature='+encodeURIComponent(signature);
Logger.log(canonical_querystring);
var request_url = endpoint + '?' + canonical_querystring;
var options = {
'method' : 'post',
'muteHttpExceptions':true,
'host': host,
}
var x = UrlFetchApp.fetch(request_url, options);
Logger.log(x);
}
Here is the Signature Generator function in GAS,
//Return Signatue (hash) from HmacSha256
function getSignature(message,secret){
var byteSignature = Utilities.computeHmacSha256Signature(message, secret);
// convert byte array to hex string
var signature = byteSignature.reduce(function(str,chr){
chr = (chr < 0 ? chr + 256 : chr).toString(16);
return str + (chr.length==1?'0':'') + chr;
},'');
return signature;
}
As you can see in the code, after generating the Signature, im appending it as a last parameter to the query string. Would that be a issue?
javascript xml amazon-web-services google-apps-script amazon-mws
This might help: docs.aws.amazon.com/general/latest/gr/…
– Dimu Designs
Nov 20 '18 at 12:40
that is for AWS, not MWS
– ScottG
Nov 20 '18 at 16:36
add a comment |
I am somehow manage to write a code as per the documentation. But unfortunately it is not working. Below is the code, have a look, please let me know what im doing wrong or missing field. I have written this code by referring someone's code.
function test(){
var date = new Date();
var amz_date = date.toISOString(); //2018-05-01T20:40:50.940Z
var yearMonthDay= Utilities.formatDate(date, 'UTC', 'yyyyMMdd');
var hourMinuteSec = Utilities.formatDate(date, 'UTC', 'HHmmss');
var dateForStringToSign = yearMonthDay +'T'+hourMinuteSec+'Z'; //20180501T204050Z
var datestamp = yearMonthDay; // 20180501
var access_key = "xxxxxxxxxxxxx";
var secret_key = "xxxxxxxxxxxxx";
var method = 'POST';
var host = 'mws.amazonservices.com';
var endpoint = 'https://mws.amazonservices.com/Orders/2013-09-01';
var canonical_uri = '/Orders/2013-09-01';
var canonical_querystring = 'AWSAccessKeyId='+encodeURIComponent('xxxxxxxxxxxxx');
canonical_querystring += '&Action='+encodeURIComponent('GetOrder');
canonical_querystring += '&AmazonOrderId.Id.1='+encodeURIComponent('xxxxxxxxxxxxx');
canonical_querystring += '&MWSAuthToken='+encodeURIComponent('xxxxxxxxxxxxx');
canonical_querystring += '&SellerId='+encodeURIComponent('xxxxxxxxxxxxx');
canonical_querystring += '&SignatureMethod='+encodeURIComponent('HmacSHA256');
canonical_querystring += '&SignatureVersion='+encodeURIComponent('2');
canonical_querystring += '&Timestamp='+encodeURIComponent(amz_date);
canonical_querystring += '&Version='+encodeURIComponent('2013-09-01');
//To construct the finished canonical request, combine all the components
var finished_canonical= method + "n"+host+"n" +canonical_uri+ "n" + canonical_querystring;
//Calculate the Signature
var signature=getSignature(finished_canonical,secret_key);
//Add signature to querystring
canonical_querystring += '&Signature='+encodeURIComponent(signature);
Logger.log(canonical_querystring);
var request_url = endpoint + '?' + canonical_querystring;
var options = {
'method' : 'post',
'muteHttpExceptions':true,
'host': host,
}
var x = UrlFetchApp.fetch(request_url, options);
Logger.log(x);
}
Here is the Signature Generator function in GAS,
//Return Signatue (hash) from HmacSha256
function getSignature(message,secret){
var byteSignature = Utilities.computeHmacSha256Signature(message, secret);
// convert byte array to hex string
var signature = byteSignature.reduce(function(str,chr){
chr = (chr < 0 ? chr + 256 : chr).toString(16);
return str + (chr.length==1?'0':'') + chr;
},'');
return signature;
}
As you can see in the code, after generating the Signature, im appending it as a last parameter to the query string. Would that be a issue?
javascript xml amazon-web-services google-apps-script amazon-mws
I am somehow manage to write a code as per the documentation. But unfortunately it is not working. Below is the code, have a look, please let me know what im doing wrong or missing field. I have written this code by referring someone's code.
function test(){
var date = new Date();
var amz_date = date.toISOString(); //2018-05-01T20:40:50.940Z
var yearMonthDay= Utilities.formatDate(date, 'UTC', 'yyyyMMdd');
var hourMinuteSec = Utilities.formatDate(date, 'UTC', 'HHmmss');
var dateForStringToSign = yearMonthDay +'T'+hourMinuteSec+'Z'; //20180501T204050Z
var datestamp = yearMonthDay; // 20180501
var access_key = "xxxxxxxxxxxxx";
var secret_key = "xxxxxxxxxxxxx";
var method = 'POST';
var host = 'mws.amazonservices.com';
var endpoint = 'https://mws.amazonservices.com/Orders/2013-09-01';
var canonical_uri = '/Orders/2013-09-01';
var canonical_querystring = 'AWSAccessKeyId='+encodeURIComponent('xxxxxxxxxxxxx');
canonical_querystring += '&Action='+encodeURIComponent('GetOrder');
canonical_querystring += '&AmazonOrderId.Id.1='+encodeURIComponent('xxxxxxxxxxxxx');
canonical_querystring += '&MWSAuthToken='+encodeURIComponent('xxxxxxxxxxxxx');
canonical_querystring += '&SellerId='+encodeURIComponent('xxxxxxxxxxxxx');
canonical_querystring += '&SignatureMethod='+encodeURIComponent('HmacSHA256');
canonical_querystring += '&SignatureVersion='+encodeURIComponent('2');
canonical_querystring += '&Timestamp='+encodeURIComponent(amz_date);
canonical_querystring += '&Version='+encodeURIComponent('2013-09-01');
//To construct the finished canonical request, combine all the components
var finished_canonical= method + "n"+host+"n" +canonical_uri+ "n" + canonical_querystring;
//Calculate the Signature
var signature=getSignature(finished_canonical,secret_key);
//Add signature to querystring
canonical_querystring += '&Signature='+encodeURIComponent(signature);
Logger.log(canonical_querystring);
var request_url = endpoint + '?' + canonical_querystring;
var options = {
'method' : 'post',
'muteHttpExceptions':true,
'host': host,
}
var x = UrlFetchApp.fetch(request_url, options);
Logger.log(x);
}
Here is the Signature Generator function in GAS,
//Return Signatue (hash) from HmacSha256
function getSignature(message,secret){
var byteSignature = Utilities.computeHmacSha256Signature(message, secret);
// convert byte array to hex string
var signature = byteSignature.reduce(function(str,chr){
chr = (chr < 0 ? chr + 256 : chr).toString(16);
return str + (chr.length==1?'0':'') + chr;
},'');
return signature;
}
As you can see in the code, after generating the Signature, im appending it as a last parameter to the query string. Would that be a issue?
javascript xml amazon-web-services google-apps-script amazon-mws
javascript xml amazon-web-services google-apps-script amazon-mws
edited Nov 21 '18 at 11:19
SIDMISH
asked Nov 20 '18 at 10:29
SIDMISHSIDMISH
56110
56110
This might help: docs.aws.amazon.com/general/latest/gr/…
– Dimu Designs
Nov 20 '18 at 12:40
that is for AWS, not MWS
– ScottG
Nov 20 '18 at 16:36
add a comment |
This might help: docs.aws.amazon.com/general/latest/gr/…
– Dimu Designs
Nov 20 '18 at 12:40
that is for AWS, not MWS
– ScottG
Nov 20 '18 at 16:36
This might help: docs.aws.amazon.com/general/latest/gr/…
– Dimu Designs
Nov 20 '18 at 12:40
This might help: docs.aws.amazon.com/general/latest/gr/…
– Dimu Designs
Nov 20 '18 at 12:40
that is for AWS, not MWS
– ScottG
Nov 20 '18 at 16:36
that is for AWS, not MWS
– ScottG
Nov 20 '18 at 16:36
add a comment |
1 Answer
1
active
oldest
votes
Read the section here called "If you create your own client library". It discusses formatting a url and signing.
Also, here is a link that might help: https://stackoverflow.com/a/36417555/3047
It didn't worked out well, im getting Signature Mismatch error, if possible can you share your contact details i will show you the process, or you can msg me on twitter @Iamsidmish . Thanks buddy! Really im stuck
– SIDMISH
Nov 21 '18 at 10:37
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53390979%2faccessing-amazon-mws-using-google-apps-script%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Read the section here called "If you create your own client library". It discusses formatting a url and signing.
Also, here is a link that might help: https://stackoverflow.com/a/36417555/3047
It didn't worked out well, im getting Signature Mismatch error, if possible can you share your contact details i will show you the process, or you can msg me on twitter @Iamsidmish . Thanks buddy! Really im stuck
– SIDMISH
Nov 21 '18 at 10:37
add a comment |
Read the section here called "If you create your own client library". It discusses formatting a url and signing.
Also, here is a link that might help: https://stackoverflow.com/a/36417555/3047
It didn't worked out well, im getting Signature Mismatch error, if possible can you share your contact details i will show you the process, or you can msg me on twitter @Iamsidmish . Thanks buddy! Really im stuck
– SIDMISH
Nov 21 '18 at 10:37
add a comment |
Read the section here called "If you create your own client library". It discusses formatting a url and signing.
Also, here is a link that might help: https://stackoverflow.com/a/36417555/3047
Read the section here called "If you create your own client library". It discusses formatting a url and signing.
Also, here is a link that might help: https://stackoverflow.com/a/36417555/3047
answered Nov 20 '18 at 13:57
ScottGScottG
5,014206894
5,014206894
It didn't worked out well, im getting Signature Mismatch error, if possible can you share your contact details i will show you the process, or you can msg me on twitter @Iamsidmish . Thanks buddy! Really im stuck
– SIDMISH
Nov 21 '18 at 10:37
add a comment |
It didn't worked out well, im getting Signature Mismatch error, if possible can you share your contact details i will show you the process, or you can msg me on twitter @Iamsidmish . Thanks buddy! Really im stuck
– SIDMISH
Nov 21 '18 at 10:37
It didn't worked out well, im getting Signature Mismatch error, if possible can you share your contact details i will show you the process, or you can msg me on twitter @Iamsidmish . Thanks buddy! Really im stuck
– SIDMISH
Nov 21 '18 at 10:37
It didn't worked out well, im getting Signature Mismatch error, if possible can you share your contact details i will show you the process, or you can msg me on twitter @Iamsidmish . Thanks buddy! Really im stuck
– SIDMISH
Nov 21 '18 at 10:37
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53390979%2faccessing-amazon-mws-using-google-apps-script%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
This might help: docs.aws.amazon.com/general/latest/gr/…
– Dimu Designs
Nov 20 '18 at 12:40
that is for AWS, not MWS
– ScottG
Nov 20 '18 at 16:36