You need to sign in to do that
Don't have an account?
Tanumay Das
Unable to request Amazon MWS Error:<SignatureDoesNotMatch>
I am trying to connect to amazon MWS and fetch some report but ever time the API produces the same error
<Code>SignatureDoesNotMatch</Code>
<Message>The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.</Message>
THE CODE
I have done every possible altaration on Signing algo,Url encoding as there docs but all were invain...
<Code>SignatureDoesNotMatch</Code>
<Message>The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.</Message>
THE CODE
Datetime now = Datetime.now().addDays(1); //String timestamp = now.formatGmt('yyyy-MM-dd')+'T'+now.formatGmt('HH:mm:ss')+'.'+now.formatGMT('SS')+'Z'; String timestamp = now.formatGmt('yyyy-MM-dd')+'T'+now.formatGmt('HH:mm:ss')+'Z'; DateTime start_dt = DateTime.newInstance(2014, 12, 16,15,21,30); DateTime end_dt = DateTime.newInstance(2014, 12, 18,14,17,21); //String start_date = start_dt.formatGmt('yyyy-MM-dd')+'T'+start_dt.formatGmt('HH:mm:ss')+'.'+start_dt.formatGMT('SS')+'Z'; //String end_date = end_dt.formatGmt('yyyy-MM-dd')+'T'+end_dt.formatGmt('HH:mm:ss')+'.'+end_dt.formatGMT('SS')+'Z'; String start_date = start_dt.formatGmt('yyyy-MM-dd')+'T'+start_dt.formatGmt('HH:mm:ss')+'Z'; String end_date = end_dt.formatGmt('yyyy-MM-dd')+'T'+end_dt.formatGmt('HH:mm:ss')+'Z'; String request = 'AWSAccessKeyId='+urlencode('-***MY CODE*****-')+ '&Action='+urlencode('RequestReport') + '&ReportType=' + urlencode( '_GET_MERCHANT_LISTINGS_DATA_') + //'&StartDate=' + urlencode(start_date) + //'&EndDate=' + urlencode(end_date)+ '&MWSAuthToken='+urlencode('-**** MY TOKEN******-')+ //'&Marketplace='+urlencode('***ID***') + '&MarketplaceIdList.Id.1='+urlencode('-****ID*****-')+ '&Merchant='+urlencode('-****ID*****-') + '&SignatureMethod='+urlencode('HmacSHA1') + '&SignatureVersion='+urlencode('2')+ '&Timestamp=' + urlencode(timestamp) + '&Version=' + urlencode('2009-01-01'); String canonical = 'GET'+'\n'+ 'mws.amazonservices.ca\n'+ '/\n'+ request; String key = '-****KEY****-'; //Signature HmacSHA256 //Blob bsig = Crypto.generateMac('HMacSHA1', Blob.valueOf(canonical), Blob.valueOf(key)); //Blob b =Crypto.generateDigest('MD5',bsig ); //Blob bsig =Crypto.generateDigest('HmacSHA256', Blob.valueOf(canonical), Blob.valueOf(key)); //Blob bsig = Crypto.encryptWithManagedIV('AES256', Blob.valueOf(key),Blob.valueOf(canonical)); //String signature = EncodingUtil.base64encode(bsig); String c = EncodingUtil.base64Encode(Blob.valueOf(canonical)); String signature ; String signingKey = EncodingUtil.base64Encode(Blob.valueOf(key)); Blob mac = Crypto.generateMac('HMacSHA1', blob.valueof(c),blob.valueof(signingKey)); signature = EncodingUtil.base64Encode(mac); //return macUrl; System.debug('String to sign===>\n' + canonical ); System.debug('Signature===>\n' + signature ); String body =request+'&Signature=' + urlEncode(signature); System.debug('canonical ===>\n' + canonical); System.debug('Body===>\n' + body ); HttpRequest req = new HttpRequest(); HttpResponse res = new HttpResponse(); Http http = new Http(); req.setCompressed(true); req.setHeader('Content-Type','text/xml'); req.setHeader('User-Agent','Salesforce'); req.setEndpoint('https://mws.amazonservices.ca/?'+body); req.setMethod('GET'); //req.setBody(body); /*req.setHeader('Host','salesforce.com'); req.setHeader('x-amazon-user-agent','cloud/1.0');*/ res = http.send(req); system.debug(res.getbody()); return null; } private String urlEncode(String rawValue) { String value = (rawValue == null) ? '' : rawValue; String encoded = null; try { encoded = EncodingUtil.urlEncode(rawValue, 'UTF-8') .replace('+', '%20') .replace('*', '%2A') .replace('%7E','~'); } catch (Exception e) { //System.err.println("Unknown encoding: " + CHARACTER_ENCODING); //e.printStackTrace(); } return encoded; }
I have done every possible altaration on Signing algo,Url encoding as there docs but all were invain...
Please try below code with HTTP Post request. It is working fine with me.
Thanks & Regards,
Jigar
We are not tring to send email.We are trying to send a request to fetch some XML response. Simply a question to ask, is there any known issue for the generatemac function of Salesforce?
Thanks,
Tanumay
No there is no any issue with generatemac function of salesforce.
Please try to replace your few lines with below.
Replace: With Below Line:
Hope it will work.
Thanks & Regards,
Jigar
I am trying to send data from salesforce to banking system. I am using HMACSha256.
Blob blobSign = Crypto.generateDigest('SHA256', Blob.valueOf(privKey + xmlOutput.length() + sfTime));
String HMACKey = EncodingUtil.base64Encode(blobSign);
I am facing the below error:
@@@Response:System.HttpResponse[Status=Forbidden, StatusCode=403]
could you please let me know is there anything wrong in my code?
Thanks in advance.
How did you fix it?
Thanks in advance