Search code examples
node.jsbalanced-payments

Problems retrieving links and properties from balanced-node module responses


I've been using the new balanced-node module for node.js, it appears to be driven by Q promises. I must not be doing something right, because when I compare the responses on the Balanced API docs to the responses I get from this plugin, they are quite different.

I'm trying to create a customer by running:

    balanced.marketplace.customers.create({
        name: "John Smith",
        email: "[email protected]",
        phone: "2222222222"
    })
    .then(function(customer) {
        // this prints out a big object which looks like the properties of the module,
        // I expected this to print out the sample response as seen in the API docs.
        console.log(customer);

        // when i run this, it prints out the actual name that was added. 
        console.log(customer.name);

        // but I can't seem to get the various source URLs that the sample response shows.
    });

Could someone give me a solid example of how to properly do this with the balanced-node module?


Solution

  • The example responses you see in the documentation are the JSON responses from cURL requests and may not be what you actually see from the client library.

    That said, to get a nicely print a formatted JSON representation of the object you should use the following method rather than console.log:

    function print(obj) {
      console.log('string' === typeof obj ? obj : JSON.stringify(obj, null, 4));
    }