Post
Topic
Board Service Discussion
Re: accessing coinbase API using node.js
by
btc junkie
on 06/05/2017, 17:21:52 UTC
Yea I already created the API keys and set the relevant permissions already.

In your code,replace the values with the keys like
Code:
var Client = require('coinbase').Client;
var client = new Client({'apiKey': DqpXhGBhLAbXdW40y, 'apiSecret': YWPcmKSbKtqgS7do49t5kBiSyA0D397C});

Shouldn't I be passing these API keys as string 'DqpXhGBhLAbXdW40y'? Otherwise it tells me DqpXhGBhLAbXdW40y is undefined.


Code:
//Should return accounts along with the ID
var coinbase = require('coinbase');
var client   = new coinbase.Client({'apiKey': DqpXhGBhLAbXdW40y, 'apiSecret': YWPcmKSbKtqgS7do49t5kBiSyA0D397C});

client.getAccounts({}, function(err, accounts) {
  accounts.forEach(function(acct) {
    console.log('my bal: ' + acct.balance.amount + ' for ' + acct.name);
  });
});

^ The above code is what I initially used but I get an error at this line since the value is still null.
Code:
 accounts.forEach(function(acct) {



*Please note that I have followed the instructions obtained from github https://github.com/coinbase/coinbase-node but I'm not sure what specific files I'm supposed to copy and where I need to place them. I'm assuming this might be the cause of the error.*

 
Here is a screenshot of my code:



and this is a screenshot of the error I got: