• Tanumay Das
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
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
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...
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
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...
Hi, I'm getting this error when trying to run databaseAccountExtractProcess bean.  I've included the process-conf.xml and database-conf.xml in the source.  Would appreciate your help to fix this.Code:
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="dbDataSource"
      class="org.apache.commons.dbcp.BasicDataSource"
      destroy-method="close">
    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
    <property name="url" value="jdbc:oracle:thin:@BTCFINAPORA2:1521:FINprod"/>
    <property name="username" value="brian"/>
    <property name="password" value="brian"/>
</bean>
<bean id="queryAccountAll"
      class="com.salesforce.lexiloader.dao.database.DatabaseConfig"
      singleton="true">
    <property name="sqlConfig" ref="queryAccountAllSql"/>
    <property name="dataSource" ref="dbDataSource"/>
</bean>
<bean id="queryAccount"
      class="com.salesforce.lexiloader.dao.database.DatabaseConfig"
      singleton="true">
    <property name="sqlConfig" ref="queryAccountSql"/>
    <property name="dataSource" ref="dbDataSource"/>
</bean>
<bean id="insertAccount"
      class="com.salesforce.lexiloader.dao.database.DatabaseConfig"
      singleton="true">
    <property name="sqlConfig" ref="insertAccountSql"/>
    <property name="dataSource" ref="dbDataSource"/>
</bean>
<bean id="updateAccount"
      class="com.salesforce.lexiloader.dao.database.DatabaseConfig"
      singleton="true">
    <property name="sqlConfig" ref="updateAccountSql"/>
    <property name="dataSource" ref="dbDataSource"/>
</bean>
<bean id="deleteAccountAll"
      class="com.salesforce.lexiloader.dao.database.DatabaseConfig"
      singleton="true">
    <property name="sqlConfig" ref="deleteAccountAllSql"/>
    <property name="dataSource" ref="dbDataSource"/>
</bean>
<bean id="queryAccountAllSql"
      class="com.salesforce.lexiloader.dao.database.SqlConfig" singleton="true">
    <property name="sqlString">
        <value>
            SELECT ACCOUNT_NAME, BUSINESS_PHONE, SFDC_ACCOUNT_ID, ACCOUNT_EXT_ID, ANNUAL_REVENUE, LAST_UPDATED, ACCOUNT_NUMBER
            FROM TableOwner.Accounts
        </value>
    </property>
    <property name="columnNames">
        <list>
            <value>account_name</value>
            <value>business_phone</value>
            <value>sfdc_account_id</value>
            <value>account_ext_id</value>
            <value>annual_revenue</value>
            <value>last_updated</value>
            <value>account_number</value>
        </list>
    </property>
</bean>
<bean id="queryAccountSql"
      class="com.salesforce.lexiloader.dao.database.SqlConfig" singleton="true">
    <property name="sqlString">
        <value>
            SELECT ACCOUNT_NAME, BUSINESS_PHONE, ACCOUNT_EXT_ID, ANNUAL_REVENUE, LAST_UPDATED, ACCOUNT_NUMBER
            FROM TableOwner.Accounts
            WHERE LAST_UPDATED > @process.lastRunDate@
        </value>
    </property>
    <property name="columnNames">
        <list>
            <value>account_name</value>
            <value>business_phone</value>
            <value>account_ext_id</value>
            <value>annual_revenue</value>
            <value>last_updated</value>
            <value>account_number</value>
        </list>
    </property>
    <property name="sqlParams">
        <map>
            <entry key="process.lastRunDate" value="java.sql.Timestamp"/>
        </map>
    </property>
</bean>
<!--- this is for updating Customers in Oracle based on SFDC Accounts -->
<bean id="updateAccountSql"
      class="com.salesforce.lexiloader.dao.database.SqlConfig" singleton="true">
    <property name="sqlString">
        <value>
            update TableOwner.Accounts accounts
               set accounts.account_name = @account_name@,
                   accounts.business_phone = @business_phone@,
                   accounts.sfdc_account_id = @sfdc_account_id@,
                   accounts.annual_revenue = @annual_revenue@,
                   accounts.account_number = @account_number@
            where
                   accounts.ACCOUNT_EXT_ID = @account_ext_id@
        </value>
    </property>
    <property name="sqlParams">
        <map>
            <entry key="account_name"    value="java.lang.String"/>
            <entry key="business_phone"  value="java.lang.String"/>
            <entry key="sfdc_account_id" value="java.lang.String"/>
            <entry key="annual_revenue"  value="java.lang.Double"/>
            <entry key="account_ext_id"  value="java.lang.String"/>
            <entry key="account_number"  value="java.lang.String"/>
        </map>
    </property>
</bean>
<bean id="XXXinsertAccountSql"
      class="com.salesforce.lexiloader.dao.database.SqlConfig" singleton="true">
    <property name="sqlString">
        <value>
            INSERT INTO TableOwner.Accounts (
               ACCOUNT_NAME, BUSINESS_PHONE, SFDC_ACCOUNT_ID, ANNUAL_REVENUE, ACCOUNT_EXT_ID, ACCOUNT_NUMBER)
            VALUES (@account_name@, @business_phone@, @sfdc_account_id@, @annual_revenue@, @account_ext_id@, @account_number@)
        </value>
    </property>
    <property name="sqlParams">
        <map>
            <entry key="account_name"    value="java.lang.String"/>
            <entry key="business_phone"  value="java.lang.String"/>
            <entry key="sfdc_account_id" value="java.lang.String"/>
            <entry key="annual_revenue"  value="java.lang.Double"/>
            <entry key="account_ext_id"  value="java.lang.String"/>
            <entry key="account_number"  value="java.lang.String"/>
        </map>
    </property>
</bean>
<bean id="insertAccountSql"
      class="com.salesforce.lexiloader.dao.database.SqlConfig" singleton="true">
    <property name="sqlString">
        <value>
            INSERT INTO brian.sfdc_de_account (
               ID)
            VALUES (@Id@)
        </value>
    </property>
    <property name="sqlParams">
        <map>
            <entry key="Id" value="java.lang.String"/>
        </map>
    </property>
</bean>
<bean id="deleteAccountAllSql"
      class="com.salesforce.lexiloader.dao.database.SqlConfig" singleton="true">
    <property name="sqlString">
        <value>
            DELETE FROM TableOwner.Accounts
        </value>
    </property>
</bean>
</beans>

 
 
2007-04-02 11:35:10,953 INFO  [main] process.ProcessConfig getBeanFactory (ProcessConfig.java:78) - Loading process configuration from config file: C:\Program Files\salesforce.com\AppExchange Data Loader 8.0\bin\..\Conf_account\process-conf.xml
2007-04-02 11:35:11,031 INFO  [main] xml.XmlBeanDefinitionReader loadBeanDefinitions (XmlBeanDefinitionReader.java:163) - Loading XML bean definitions from file [C:\Program Files\salesforce.com\AppExchange Data Loader 8.0\bin\..\Conf_account\process-conf.xml]
2007-04-02 11:35:11,078 INFO  [main] core.CollectionFactory <clinit> (CollectionFactory.java:66) - JDK 1.4+ collections available
2007-04-02 11:35:11,093 INFO  [main] core.CollectionFactory <clinit> (CollectionFactory.java:71) - Commons Collections 3.x available
2007-04-02 11:35:11,187 INFO  [databaseAccountExtract] controller.Controller initConfig (Controller.java:350) - The controller config has been initialized
2007-04-02 11:35:11,203 INFO  [databaseAccountExtract] process.ProcessRunner run (ProcessRunner.java:102) - Initializing process engine
2007-04-02 11:35:11,203 INFO  [databaseAccountExtract] process.ProcessRunner run (ProcessRunner.java:105) - Loading parameters
2007-04-02 11:35:12,390 INFO  [databaseAccountExtract] process.ProcessRunner run (ProcessRunner.java:116) - Logging in to: https://www.salesforce.com
2007-04-02 11:35:13,296 INFO  [databaseAccountExtract] dao.DataAccessObjectFactory getDaoInstance (DataAccessObjectFactory.java:51) - Instantiating data access object: insertAccount of type: databaseWrite
2007-04-02 11:35:13,312 INFO  [databaseAccountExtract] xml.XmlBeanDefinitionReader loadBeanDefinitions (XmlBeanDefinitionReader.java:163) - Loading XML bean definitions from file [C:\Program Files\salesforce.com\AppExchange Data Loader 8.0\bin\..\Conf_account\database-conf.xml]
2007-04-02 11:35:13,375 INFO  [databaseAccountExtract] process.ProcessRunner run (ProcessRunner.java:121) - Checking the data access object connection
2007-04-02 11:35:14,187 INFO  [databaseAccountExtract] process.ProcessRunner run (ProcessRunner.java:126) - Setting field types
2007-04-02 11:35:15,359 INFO  [databaseAccountExtract] process.ProcessRunner run (ProcessRunner.java:130) - Setting object reference types
2007-04-02 11:35:23,312 INFO  [databaseAccountExtract] process.ProcessRunner run (ProcessRunner.java:134) - Creating Map
2007-04-02 11:35:23,312 INFO  [databaseAccountExtract] action.ActionFactory getActionInstance (ActionFactory.java:64) - Instantiating operation: extract
2007-04-02 11:35:23,328 INFO  [databaseAccountExtract] controller.Controller executeAction (Controller.java:130) - executing operation: extract
2007-04-02 11:35:27,343 FATAL [databaseAccountExtract] database.DatabaseContext setSqlParamValues (DatabaseContext.java:183) - Error getting value for SQL parameter: Id.  Please make sure that the value exists in the configuration file or is passed in.  Database configuration: insertAccount.
2007-04-02 11:35:27,343 INFO  [databaseAccountExtract] progress.NihilistProgressAdapter setSubTask (NihilistProgressAdapter.java:68) - Processed 500 of 126019 total records. Rate: 120000000 records per hour. Estimated time to complete: 0 minutes and 0 seconds.  There are 0 successes and 500 errors.
2007-04-02 11:35:28,343 FATAL [databaseAccountExtract] database.DatabaseContext setSqlParamValues (DatabaseContext.java:183) - Error getting value for SQL parameter: Id.  Please make sure that the value exists in the configuration file or is passed in.  Database configuration: insertAccount.