Http post issue - gengo

Hi,

I’m having an issue with the HTTP.call() method. I’m pretty sure I have done something stupid, but cannot work it out. I’m trying to create a new job on a service called Gengo, and the code to do it looks like (from here, in Python):

# random header stuff
if __name__ == '__main__':
    PUBLIC_KEY = 'your public key'
    PRIVATE_KEY = 'your private key'

    URL = "http://api.gengo.com/v2/translate/service/language_pairs"
    header = {"Accept": "application/json"}

    data = {
        "api_key": PUBLIC_KEY,
        "api_sig": PRIVATE_KEY,
        "ts": str(int(time.time()))
    }
    # use your private_key to create an hmac
    data["api_sig"] = hmac.new(
        data["api_sig"],
        data["ts"],
        sha1
    ).hexdigest()

    get_language_pair = requests.get(URL, headers=header, params=data)
    res_json = json.loads(get_language_pair.text)
    if not res_json["opstat"] == "ok":
        msg = "API error occured.\nerror msg: {0}".format(
            res_json["err"]
        )
        raise AssertionError(msg)
    else:
        print(res_json)

OK - so nothing hugely complex. some headers + params, no worries. Why is my below not working?

case ('postJobs'): {
const crypto = require('crypto');

          const method = 'POST';
          const url = 'http://api.sandbox.gengo.com/v2/translate/jobs';

          const publicKey = Meteor.settings.private.gengo.publicKey;
          const privateKey = Meteor.settings.private.gengo.privateKey;
          const ts = new Date() / 1000 | 0;

          const headers = {
            'Accept': 'application/json',
          };

          const params = {
            api_key: publicKey,
            api_sig: crypto.createHmac('sha1', privateKey).update(ts.toString()).digest('hex'),
            ts: ts,
          };

          const data = {
            jobs: {
              job_1: {
                type: 'text',
                body_src: 'one two three four',
                lc_src: 'en',
                lc_tgt: 'ja',
                tier: 'standard',
                auto_approve: 1,
              },
              job_2: {
                type: 'text',
                body_src: 'Hello World',
                lc_src: 'en',
                lc_tgt: 'ja',
                tier: 'standard',
                auto_approve: 1,
              },
            },
            comment:'Instructions for translators on the entire order go here',
          };

          return await HTTP.call(method, url, { headers, params, data });
}

Error: Basically, am I blind? Have I missed something really simple? The error says I am not sending in a jobs array. Clearly I am sending in a jobs array?

Image below shows the getLanguagePairsPromise working, and the postJobsPromise failing.

Any ideas much appreciated? Maybe I am doing something odd with the HTTP.call()? Thanks so much.

Tat

For completeness: doing something similar with getLanguagePairsPromise works fine.

case ('getLanguagePairs'): {
          const crypto = require('crypto');

          const publicKey = Meteor.settings.private.gengo.publicKey;
          const privateKey = Meteor.settings.private.gengo.privateKey;
          const ts = new Date() / 1000 | 0;

          const method = 'GET';
          const url = 'http://api.sandbox.gengo.com/v2/translate/service/language_pairs';

          const headers = {
            'Content-Type': 'application/json',
          };

          const params = {
            api_key: publicKey,
            api_sig: crypto.createHmac('sha1', privateKey).update(ts.toString()).digest('hex'),
            ts: ts,
          };

          return await HTTP.call(method, url, { headers, params });
        }

Other: There is a npm package that does this, but has no tests, here. The code again looks really simple, so apparently I’m a putz.

Thanks for looking at this…