Mono Node.js Library
The Mono Node library provides convenient access to the Mono API from applications written in server-side JavaScript.
For connecting customer accounts in the browser or an app, use the Mono Connect Widget.
Documentation
For complete information about the API, head to the docs.
Getting Started
- Register on the Mono website and get your public and secret keys.
- Setup your Mono Connect Widget with your Mono public key.
Installation
Install the package with:
npm install mono-node --save
# or
yarn add mono-node
Usage
The package needs to be configured with your account's secretKey
, which is
available in the Mono Dashboard.
// import the module
const { Mono } = require("mono-node");
// set the secret key
const monoClient = new Mono({
secretKey: "test_sk_...",
});
// get your Mono Wallet balance
monoClient.user.walletBalance((err, results) => {
// Handle errors
if (err) {
console.log(err);
}
if (results){
console.log(results);
};
});
Features
- Wallet Balance
- Get Account ID from Auth Code
- Unlink Account
- Account Information
- Account Statement
- Poll Account Statement PDF
- Transactions
- Credits
- Debits
- Income Information
- Identity
- Sync Data
- Re-auth Code
- Institutions
Implementation
Methods
Once an instance of the client has been created you use the following methods:
Get Wallet Balance
This resource allows you to check the available balance in your Mono wallet
monoClient.user.walletBalance(callback);
Get Account Id from token
This resource returns the account id (that identifies the authenticated account) after successful enrolment on the Mono Connect Widget.
monoClient.auth.getAccountId({code: String}, callback);
Unlink Account
This resource provides your customers with the option to unlink their financial account(s)
monoClient.account.unlinkAccount({accountId: String}, callback);
Get Account Information
This resource returns the account details with the financial institution.
monoClient.account.getAccountInformation({accountId: String}, callback);
Get Account Statement in JSON
This resource returns the bank statement of the connected financial account in JSON.
You can query 1-12 months bank statement in one single call.
monoClient.account.getAccountStatement({accountId: String, output: 'json'}, callback);
Get Account Statement in PDF
This resource returns the bank statement of the connected financial account in PDF.
You can query 1-12 months bank statement in one single call.
monoClient.account.getAccountStatement({accountId: String, output: 'pdf'}, callback);
Poll Account Statement in PDF
With this resource, you set the output as PDF, and you can use this endpoint to poll the status
monoClient.account.pollPdfAccountStatementStatus({accountId: String, jobId: Striing}, callback);
Get Account Transactions
This resource returns the known transactions on the account.
monoClient.account.getAccountTransactions({accountId: String, type: 'credit'}, callback);
Get Customer's Credits
This resource returns the historical credits on the account
monoClient.account.getCustomerCredits({accountId: String}, callback);
Get Customer's Debits
This resource returns the historical debits on the account
monoClient.account.getCustomerDebits({accountId: String}, callback);
Get Income Information
This resource will return income information on the account.
monoClient.account.getIncome({accountId: String}, callback);
Get Account Identity
This resource returns a high level overview of an account identity data.
monoClient.account.getIdentity({accountId: String}, callback);
Synchronise Data
This resource attempts to Sync data manually.
monoClient.account.syncDataManually({accountId: String}, callback);
Get Re-auth Code.
This resource returns a Re-auth code which is a mono generated code for the account you want to re-authenticate,
monoClient.account.reauthCode({accountId: String}, callback);
Get Financial Institutions
This resource returns the available institutions on Mono
monoClient.misc.institutions(callback);
Callbacks
All requests have callbacks of the following form:
function callback(err, results) {
// Handle errors
if (err) {
console.log(err);
}
if (results){
console.log(results);
};
}
Error Handling
The err
argument passed to the callback is a Mono API error.
function callback(err, results) {
if (err != null) {
console.log(err)
}
}
Examples
Exchange an auth code
from Mono Connect Widget for an accountId
and then retrive account data:
Note: If the meta data_status
is still in the processing stage, you have to wait before calling the APIs below e.g Statement, Transaction, Income and Identity Endpoints. Some banks are faster than others, so it may be available instantly after authorization and some banks might take a few seconds or minutes.
// code from Mono Connect Widget
const authCode = 'RANDOM_CODE'
monoClient.auth.getAccountId({code: authCode}, (err, results) => {
const accountId = results.id
monoClient.account.getAccountInformation({accountId: accountId}, (err, results) => {
console.log(results.account)
if(results.meta.data_status == 'AVAILABLE'){
console.log('Account data ready for use.')
}
});
});
Get account transactions for the last thirty days:
const now = moment();
const today = now.format('DD-MM-YYYY');
const thirtyDaysAgo = now.subtract(30, 'days').format('DD-MM-YYYY');
monoClient.account.getAccountTransactions({accountId: String, start: today, end: thirtyDaysAgo, paginate: false}, (err, results) => {
console.log(`You have ${results.data.length} transactions from the last thirty days.`);
});
Get income for an account:
Note: This is a number estimated by Mono. It is not nesecarrily 100% correct, however, a confidence interval is provided to show the estimations accuracy.
monoClient.account.getIncome({accountId: String}, (err, results) => {
console.log(`Your ${results.type} is ${results.amount}. You work at ${results.employer}`);
});
Get an identity for an account:
Note: Not all banks return identity information. See Coverage
monoClient.account.getIdentity({accountId: String}, (err, results) => {
console.log(`Your ${results.type} is ${results.amount}. You work at ${results.employer}`);
});
Manual data sync for an account:
Note: This may require some users to re-authorize their bank account with Mono. See Re-authorization
monoClient.account.syncDataManually({accountId: String}, (err, results) => {
console.log(`Status: ${results.status}`);
});
Get re-auth code for an account:
Note: Please note that this Re-auth code/token expires in 10 minutes. You will need to pass the re-auth code to a Mono Connect Widget to complete verification.
monoClient.account.reauthCode({accountId: String}, (err, results) => {
console.log(results.token);
});
Unlink a bank account:
It is strongly recommend to implement this feature to build trust with your users and allow them to have complete control of their data. See Docs
monoClient.account.unlinkAccount({accountId: String}, (err, results) => {
console.log(results.message);
});
Support
If you're having general trouble with Mono Node.js or your Mono integration, please reach out to us at hi@mono.co or come chat with us on Slack. We're proud of our level of service, and we're more than happy to help you out with your integration to Mono.
Contributing
If you would like to contribute to the Mono Node.js Library, please make sure to read our contributor guidelines.
License
MIT for more information.