0

I am trying to create a Hit on Amazon mechanical turk. I am currently using Meteor, so I don't have an SDK (that I know of) that I can use.

In order to create the hit, I am using the following code:

Mturk.createHit = function(jobAttributes) {

    var operation = "CreateHIT";
    var service = "AWSMechanicalTurkRequester";
    var timestamp = moment().toISOString();
    var encoded = CryptoJS.HmacSHA256(service + operation + timestamp, process.env.SECRET_ACCESS_KEY).toString();

    var hitResponse = Meteor.http.get(
        "https://mechanicalturk.sandbox.amazonaws.com",
        {
            params: {
                Service: service,
                AWSAccessKeyId: process.env.ACCESS_KEY_ID,
                Version: "2013-11-15",
                Operation: operation,
                Signature: encoded,
                Timestamp: timestamp,
                Title: 'Survey',
                Description: 'Survey Description',
                Reward: {
                    Amount: 5,
                    CurrencyCode: 'USD'
                }
            }
        }
    );

    console.log(hitResponse);
}

Every time I submit this, I get the following error:

AWS.BadClaimsSupplied The specified claims are invalid. Based on your request, your signature should be generated using the following string: AWSMechanicalTurkRequesterCreateHITs2014-11-13T05:41:31.357Z. Check to make sure your system clock and timezone is not incorrect. Our current system time: 2014-11-13T05:41:31Z.

I think that the error is coming from improperly creating my signature, but I am not sure exactly how to proceed. I have tried using base64 encoding, but that hasn't worked for me either. Any ideas?

David Mckee
  • 1,100
  • 3
  • 19
  • 35
  • Are you able to get a simpler request to work (e.g., GetAccountBalance)? Usually this is the result of the wrong timestamp format or the wrong API access key ID and/or secret key. – Thomas Nov 13 '14 at 07:37
  • @Thomas I haven't been able to get anything to work. – David Mckee Nov 13 '14 at 16:19
  • I am trying the same in PHP and seeing the same error. Changing SHA256 to SHA1 fixed it for me. I also had to add a parameter SignatureMethod=HmacSHA1 – saintsjd Apr 08 '15 at 06:12

0 Answers0