Playing around with Balanced-Payments API Trying to wrap my head around the way their Node.js lib is constructed. I am a relative newcomer to JS so I am still tripping over promises.
When using code straight from their example for listing customers http://docs.balancedpayments.com/1.1/api/customers/#list-all-customers I am kind of at a loss looking at their syntax for balanced.marketplace.customers
It's not a function that returns a value and when I tried console.log(balanced.marketplace.customers)I get { [Function: act] _promised_something: 'customers' } I've been racking my brains as to how to use this approach as a standard PROMISE.then(something) approach doesn't seem to make sense here.
Thanks in advance for any help on this usage of promises.
The proper syntax is:
balanced.marketplace.customers.then(function(data){
console.log(data);
});
However, if you would like to pretty print out the json object that's returned you'll need to add a method such as:
function print(obj) {
console.log('string' === typeof obj ? obj : JSON.stringify(obj, null, 4));
}
This would replace the console.log in the first code example.