Balanced Payments Account debit not working with Node.js

Problem

I am trying to do an account credit request with Node.js using the following example. But it fails even when I use the sample code without any change. https://docs.balancedpayments.com/current/overview.html?language=node#charge-a-credit-card

balanced.Accounts.get("/v1/marketplaces/TEST-MP60c88vnFHzgzEyzGcbMKic/accounts/AC1a77avbmVTUt8pciwDlMJW/debits", function(err, result) {
var user = balanced.Accounts.nbalanced(result);
user.Debits.create({ amount: 1000 }, function(err, result) {
/* . . . */
});

});

It fails after this statement is executed...

var user = balanced.Accounts.nbalanced(result);

The error message I get is...

The following properties are required and are missing or null (id).

Here is the full stack trace...

C:\Users\Nabeel\GroupFund\node\node_modules\balanced-official\lib\nbalanced\validate.js:112
if (!callback) throw error;
                     ^
The following properties are required and are missing or null (id).
Problem courtesy of: nabeel

Solution

I found the mistake in the sample code given in the documentation. All I had to do was omit the /debits from the uri in balanced.Accounts.getcall...

The following code works...

    balanced.Accounts.get("/v1/marketplaces/TEST-MP60c88vnFHzgzEyzGcbMKic/accounts/AC1a77avbmVTUt8pciwDlMJW", function(err, result) {
    var user = balanced.Accounts.nbalanced(result);
    user.Debits.create({ amount: 1000 }, function(err, result) {
    /* . . . */
    });
});
Solution courtesy of: nabeel

Discussion

The original issue, yes, was that the example supplied the account debits URI when it should have been the account URI.

These examples have been updated in the Balanced documentation to now use the Customer resource. They should also now be self-contained runnable examples. See https://docs.balancedpayments.com/current/?language=node#charge-a-credit-card

Discussion courtesy of: Remear

This recipe can be found in it's original form on Stack Over Flow.