• Grainne Ryan
  • NEWBIE
  • 40 Points
  • Member since 2016

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 11
    Replies
Hi Guys ,
Can we consume Amazon Marketplace Web Service from salesforce and create listings and fetch orders .
  • June 17, 2017
  • Like
  • 0
Hi
I am trying to bring Amazon orders into Salesforce using the Amazon webservice but I keep getting the same error 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.

But the signature I send is correct. I know because I have used Amazon MWS Scratchpad (this works perfectly) and when I use the timestamp from this in my program I get the same signature.  

I have no idea what else to do and I would appreciate any suggestions though I am 100% certain that I am using the correct information (access key, secret key etc.) from Amazon
My code is below
Thanks
Gráinne
 public static void Listorder() {

        //Current time in GMT ISO 8601
        String timestamp = datetime.now().formatGMT('yyyy-MM-dd\'T\'HH:mm:ss.SSS\'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= 'amazon marketplace id';
        String fulfillmentChannel = 'AFN';
        String sellerId = 'amazon seller id';
        String endpoint = 'https://mws.amazonservices.com/Orders/2013-09-01';
        String accessKey = 'amazon access key';
        String amazonSecretKey = 'amazon secret key';
    
        //Construct a query string with the query information
        String queryString = 'AWSAccessKeyId=' + accessKey + 
            '&Action=' + action  +
            '&CreatedAfter=2016-09-30T23%3A00%3A00Z' + 
            '&MarketplaceId.Id.1=' + MarketplaceId  +
            '&SellerId=' + SellerId +
            '&SignatureMethod=' + SignatureMethod  +
            '&SignatureVersion=' + SignatureVersion  +
            '&Timestamp=' + timestamp  +
            '&Version=' + version ;

        String stringtoSign = 'POST' + '\n' +
            'mws.amazonservices.co.uk' + '\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);
     
        HttpRequest req = new HttpRequest();    
        
        req.setEndpoint(endpoint +'?AWSAccessKeyId=' + accessKey +
            '&Action=' + action +
            '&SellerId=' + sellerId +
            '&SignatureVersion=2' +
            '&Timestamp=' + timestamp +
            '&Version=' + version +
            '&Signature=' + signature +
            '&SignatureMethod='+ signatureMethod +
            '&CreatedAfter=2016-09-30T23%3A00%3A00Z' +
            '&MarketplaceId.Id.1=' + marketplaceId);
        
        req.setMethod('POST');
        
        Http http = new Http();
        try {
            HttpResponse res = http.send(req);
            System.debug(res.getStatus());
            System.debug(res.getStatusCode());
            System.debug(res.getBody());
            } 
        catch(System.CalloutException e) {
            System.debug(e);
        }

   }


 
I know that this question has been asked a lot but none of the proposed solutions helped me.

When I try to access salesforce with the access token I get an error
 "The REST API is not enabled for this organization" "API_DISABLED_FOR_ORG"
I have a developer's edition trial and API is enabled.

I got an access token through curl using "grant_type=password" and then tried to access Salesforce like this:
        curl -v https://eu6.salesforce.com/services/data/v20.0  -H "Authorization: Bearer <access_token>" 

Is this not correct or is there something else I should do?  

Any help would be greatly appreciated.
Thank you
 
Hi Guys ,
Can we consume Amazon Marketplace Web Service from salesforce and create listings and fetch orders .
  • June 17, 2017
  • Like
  • 0
Hi
I am trying to bring Amazon orders into Salesforce using the Amazon webservice but I keep getting the same error 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.

But the signature I send is correct. I know because I have used Amazon MWS Scratchpad (this works perfectly) and when I use the timestamp from this in my program I get the same signature.  

I have no idea what else to do and I would appreciate any suggestions though I am 100% certain that I am using the correct information (access key, secret key etc.) from Amazon
My code is below
Thanks
Gráinne
 public static void Listorder() {

        //Current time in GMT ISO 8601
        String timestamp = datetime.now().formatGMT('yyyy-MM-dd\'T\'HH:mm:ss.SSS\'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= 'amazon marketplace id';
        String fulfillmentChannel = 'AFN';
        String sellerId = 'amazon seller id';
        String endpoint = 'https://mws.amazonservices.com/Orders/2013-09-01';
        String accessKey = 'amazon access key';
        String amazonSecretKey = 'amazon secret key';
    
        //Construct a query string with the query information
        String queryString = 'AWSAccessKeyId=' + accessKey + 
            '&Action=' + action  +
            '&CreatedAfter=2016-09-30T23%3A00%3A00Z' + 
            '&MarketplaceId.Id.1=' + MarketplaceId  +
            '&SellerId=' + SellerId +
            '&SignatureMethod=' + SignatureMethod  +
            '&SignatureVersion=' + SignatureVersion  +
            '&Timestamp=' + timestamp  +
            '&Version=' + version ;

        String stringtoSign = 'POST' + '\n' +
            'mws.amazonservices.co.uk' + '\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);
     
        HttpRequest req = new HttpRequest();    
        
        req.setEndpoint(endpoint +'?AWSAccessKeyId=' + accessKey +
            '&Action=' + action +
            '&SellerId=' + sellerId +
            '&SignatureVersion=2' +
            '&Timestamp=' + timestamp +
            '&Version=' + version +
            '&Signature=' + signature +
            '&SignatureMethod='+ signatureMethod +
            '&CreatedAfter=2016-09-30T23%3A00%3A00Z' +
            '&MarketplaceId.Id.1=' + marketplaceId);
        
        req.setMethod('POST');
        
        Http http = new Http();
        try {
            HttpResponse res = http.send(req);
            System.debug(res.getStatus());
            System.debug(res.getStatusCode());
            System.debug(res.getBody());
            } 
        catch(System.CalloutException e) {
            System.debug(e);
        }

   }


 
I know that this question has been asked a lot but none of the proposed solutions helped me.

When I try to access salesforce with the access token I get an error
 "The REST API is not enabled for this organization" "API_DISABLED_FOR_ORG"
I have a developer's edition trial and API is enabled.

I got an access token through curl using "grant_type=password" and then tried to access Salesforce like this:
        curl -v https://eu6.salesforce.com/services/data/v20.0  -H "Authorization: Bearer <access_token>" 

Is this not correct or is there something else I should do?  

Any help would be greatly appreciated.
Thank you