Author

Topic: accessing coinbase API using node.js (Read 420 times)

legendary
Activity: 1988
Merit: 1317
Get your game girl
May 07, 2017, 01:40:11 PM
#6
Try the following code and let me know if that works.I don't really want to run the app locally so it will be better if you add on skype or something,much better to solve in real time.
Code:
client.getAccounts({}, function(err, accounts) {
  accounts.forEach(function(acct) {
    console.log(acct.name + ': ' + acct.balance.amount + ' ' + acct.balance.currency);
    acct.getTransactions(null, function(err, txns) {
      txns.forEach(function(txn) {
        console.log('txn: ' + txn.id);
      });
    });
  });
});

Yes that API keys should be passed a string only.

The error occurs at this line
Code:
accounts.forEach(function(acct) {
the extra code added comes after the error occurs and the app has already crashed.
Pretty sure you're doing something wrong.Have tested the network part in the console ? Is it receiving any data back ? Want me to take a look through teamviewer ? Otherwise I'll implement it locally tomorrow and check where you're going wrong..
sr. member
Activity: 265
Merit: 250
May 07, 2017, 01:36:59 PM
#5
Try the following code and let me know if that works.I don't really want to run the app locally so it will be better if you add on skype or something,much better to solve in real time.
Code:
client.getAccounts({}, function(err, accounts) {
  accounts.forEach(function(acct) {
    console.log(acct.name + ': ' + acct.balance.amount + ' ' + acct.balance.currency);
    acct.getTransactions(null, function(err, txns) {
      txns.forEach(function(txn) {
        console.log('txn: ' + txn.id);
      });
    });
  });
});

Yes that API keys should be passed a string only.

The error occurs at this line
Code:
accounts.forEach(function(acct) {
the extra code added comes after the error occurs and the app has already crashed.
legendary
Activity: 1988
Merit: 1317
Get your game girl
May 07, 2017, 05:56:07 AM
#4
Try the following code and let me know if that works.I don't really want to run the app locally so it will be better if you add on skype or something,much better to solve in real time.
Code:
client.getAccounts({}, function(err, accounts) {
  accounts.forEach(function(acct) {
    console.log(acct.name + ': ' + acct.balance.amount + ' ' + acct.balance.currency);
    acct.getTransactions(null, function(err, txns) {
      txns.forEach(function(txn) {
        console.log('txn: ' + txn.id);
      });
    });
  });
});

Yes that API keys should be passed a string only.
sr. member
Activity: 265
Merit: 250
May 06, 2017, 12:21:52 PM
#3
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:





legendary
Activity: 1988
Merit: 1317
Get your game girl
May 06, 2017, 02:31:15 AM
#2
I'm having problems doing the simplest tasks such as displaying balance. I'm no pro at node.js but I think I should know enough to do this. Is anyoine familiar with the coinbase node.js API?

 Their website contains some basic code for listing accounts but this always returns NULL when I run it:

        var Client = require('coinbase').Client;
        var client = new Client({'apiKey': 'myApiKeyHere',
                         'apiSecret': 'myApiSecretHere'});

        client.getAccounts({}, function(err, accounts) {
          console.log(accounts);
        });
->Make an account at coinbase,did you ?
-> Open the following link once logged in : https://www.coinbase.com/settings/api
->Click + New Api Key ->Enter your password ->Select all API wallets for which you suppose to write the code.
->Under Permissions : Tick whatever that applies for your application:
Code:
wallet:accounts:create wallet:accounts:delete
wallet:accounts:read wallet:accounts:update
wallet:addresses:create wallet:addresses:read
wallet:buys:create wallet:buys:read
wallet:checkouts:create wallet:checkouts:read
wallet:contacts:read wallet:deposits:create
wallet:deposits:read wallet:notifications:read
wallet:orders:create wallet:orders:read
wallet:orders:refund wallet:payment-methods:delete

Depending on your selection the API would get the details.After clicking create,you will be have a pop-up which displays your API key and API secret.Something like,
Does anyone have any experience with using this API? I'm willing to offer a $15 tip or more in btc if someone can help me with this API and some of the other node.js APIs. If you are willing to teach me this stuff for a higher fee then feel free to PM me about it. But I'm running on a low budget so I'm not in a position to pay the price of hiring a professional node.js developer.

Send me a message .I'll be more than happy to teach you things.
sr. member
Activity: 265
Merit: 250
May 06, 2017, 12:27:13 AM
#1
I'm having problems doing the simplest tasks such as displaying balance. I'm no pro at node.js but I think I should know enough to do this. Is anyoine familiar with the coinbase node.js API?

 Their website contains some basic code for listing accounts but this always returns NULL when I run it:

        var Client = require('coinbase').Client;
        var client = new Client({'apiKey': 'myApiKeyHere',
                         'apiSecret': 'myApiSecretHere'});

        client.getAccounts({}, function(err, accounts) {
          console.log(accounts);
        });

Does anyone have any experience with using this API? I'm willing to offer a $15 tip or more in btc if someone can help me with this API and some of the other node.js APIs. If you are willing to teach me this stuff for a higher fee then feel free to PM me about it. But I'm running on a low budget so I'm not in a position to pay the price of hiring a professional node.js developer.
Jump to: