You need to sign in to do that
Don't have an account?
Sibasish Panigrahi
Signature Doesn't Match Error In Integration With Amazon
I'm trying to integrate amazon with salesforce since day's but got stucked. Although i'm providing the correct "Access Key", "Security Key", "Token" etc, the error keeps on popping up.
Can anyone help me to figure out where i'm wrong?
Can anyone help me to figure out where i'm wrong?
List<AmazonMWS__c> amazonList = AmazonMWS__c.getall().values(); //Current time in GMT ISO 8601 String timestamp = datetime.now().formatGMT('yyyy-MM-dd\'T\'HH:mm:ss\'Z\''); timestamp = EncodingUtil.urlEncode(timestamp,'UTF-8'); //Amazon Variables String action = 'ListOrders'; String version = '2013-09-01'; String signatureVersion = '2'; String signatureMethod = 'HmacSHA256'; String marketplaceId= amazonList[0].Marketplace_ID__c; String marketplaceToken = amazonList[0].MWSAuthToken__c; String fulfillmentChannel = 'AFN'; String sellerId = amazonList[0].Seller_ID__c; String endpoint = 'https://mws.amazonservices.com/Orders/2013-09-01'; String accessKey = amazonList[0].AWSAccessKey__c; String amazonSecretKey = amazonList[0].Secret_Key__c; //Construct a query string with the query information String queryString = 'AWSAccessKeyId=' + accessKey + '&Action=' + action + '&SellerId=' + sellerId + '&MWSAuthToken=' + marketplaceToken + '&SignatureVersion=' + signatureVersion + '&Timestamp=' + timestamp + '&Version=' + version + '&SignatureMethod=' + signatureMethod + '&CreatedAfter=2016-09-28T18%3A30%3A00Z' + '&MarketplaceId.Id.1=' + marketplaceId ; String stringtoSign = 'POST' + '\n' + 'mws.amazonservices.com' + '\n' + '/Orders/2013-09-01' + '\n' + queryString; //Covert query string to signature using Amazon secret key as key Blob mac = Crypto.generateMac('HMacSHA256', blob.valueof(stringtoSign),blob.valueof(amazonSecretKey)); String signature = EncodingUtil.base64Encode(mac); signature = EncodingUtil.urlEncode(signature,'UTF-8'); system.debug('signature '+signature); HttpRequest req = new HttpRequest(); req.setEndpoint(endpoint +'?AWSAccessKeyId=' + accessKey + '&Action=' + action + '&SellerId=' + sellerId + '&MWSAuthToken=' + marketplaceToken + '&SignatureVersion=2' + '&Timestamp=' + timestamp + '&Version=' + version+ '&Signature=' + signature + '&SignatureMethod='+ signatureMethod+ '&CreatedAfter=2016-09-28T18%3A30%3A00Z' + '&MarketplaceId.Id.1=' + marketplaceId); req.setMethod('POST'); system.debug('req'+req); Http http = new Http(); HttpResponse res = http.send(req); system.debug(res.getStatus()); system.debug(res.getStatusCode()); system.debug(res.getBody());
Best Answer chosen by Sibasish Panigrahi
Sibasish Panigrahi
Solved the issue. Everything was correct but the "queryString" and "req.setEndpoint" was not arranged properly. I checked in scratchpad and arranged accordingly. Now its working.