Tuesday 16 May 2017

TypeError: First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object. using API nodejs

Trying to get list of transactions from Gdax API (link): Here is the documentation for the method:

var accountID = '7d0f7d8e-dd34-4d9c-a846-06f431c381ba';
authedClient.getAccountHistory(accountID, callback);
// For pagination, you can include extra page arguments
authedClient.getAccountHistory(accountID, {'before': 3000}, callback);
self.getTransactions = function(options, callback) {
  var transactions;
  var key = options.key;
  var b64secret = options.secret;
  var passphrase = options.passphrase;

  var Gdax = require('gdax');
  var authedClient = new Gdax.AuthenticatedClient(
    key, b64secret, passphrase);

  var accountID = '32fb94c4-cda2-52f1-9bae-1866a0605789';
  authedClient.getAccountHistory(accountID, function(err, response, transactions) {
    details = {
      timestamp: util.timestampNow(),
      error: err.message,
      data: []
    };
    if (err || resp.statusCode !== 200) {
      let error = err || new Error(`Error ${resp.statusCode}: ${resp.body}`);
      result.error = error.message;
      return callback(error, result);
    }
    _.each(transactions, function(transaction) {
      let data = {
        transaction_id: transaction.id,
        total: transaction.amount,
        type: transaction.type
      };
      details.data.push(data);
    });
  });
  callback(err, transactions);
};

Logging this error:

(node:24588) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 8): TypeError: First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.



via chuckieDub

No comments:

Post a Comment