Send request parameters from JSON with PUT request using Meteor.http.call()


#1

Code below:

    function getAddress() {
          var kite = Meteor.npmRequire('coinkite-javascript'); 
          sign = kite.auth_headers('somekey', 'somesecret', '/v1/new/receive');
          console.log(kite.auth_headers('somekey', 'somesecret', '/v1/new/receive'));
          console.log(Meteor.http.call("PUT", "https://api.coinkite.com/v1/new/receive", { params: { account: 'CA8A4C1B40-359DC0' } + sign}));
        };
    Meteor.startup(function () {
        getAddress();

    });

Anyhow, this code is not working for some reason.
While the JSON object returned by the key generator (sign) is:

{ ‘X-CK-Key’: ‘somekey’,‘X-CK-Sign’: ‘3655960c6ad67a0f3d57cd9468d375defcdae96587e6b5778e6dbbb9b6470568’,
‘X-CK-Timestamp’: ‘2015-05-12T01:09:55.551Z’ }

the request returns a 401 saying the X-CK-KEY is not defined.

How can I effectively add these parameters to the put request?


#2

According to the documentation I think you need to specify the data in options

HTTP.call(method, url, [options], [asyncCallback])

where options should be

options = {data: {  params: { account: 'CA8A4C1B40-359DC0' } + sign} }

#3

Mm that makes sense but its not working for some reason.

          console.log(Meteor.http.call("PUT", "https://api.coinkite.com/v1/new/receive", options = {data: {  params: { account: 'CA8A4C1B40-359DC0' } + sign} }));

Still thinks the CK key is missing - from the docs it sounds like parameters are not supported on a PUT request but thats not compliant with HTTP spec


#4

Hmm, I can’t find where it says that PUT doesn’t support data. What does the return object look like?


#5

You can’t merge two objects together in JavaScript with the + operator. You could consider using _.extend():

var params = _.extend(sign, {account: 'CA8A4C1B40-359DC0'})

Although for the sake of a single additional property, I’d probably just use:

sign.account = 'CA8A4C1B40-359DC0';

and use sign as the params:

Meteor.http.call("PUT", "https://api.coinkite.com/v1/new/receive", { params: sign});

#6

Duh! I totally missed that.