GithubHelp home page GithubHelp logo

twang2218 / node-cba-netbank Goto Github PK

View Code? Open in Web Editor NEW
74.0 12.0 25.0 824 KB

Unofficial The Commonwealth Bank of Australia NetBank API wrap for Node.js

License: Apache License 2.0

JavaScript 23.25% HTML 76.75%
banking cba js node cli api

node-cba-netbank's Introduction

node-cba-netbank

NPM version MIT License Build Status Dependency Status Coverage Status

NPM

Unofficial The Commonwealth Bank of Australia NetBank API wrap for Node.js

Usage

CLI

Install

npm install node-cba-netbank -g

Usage

$ cba-netbank --help
CBA Netbank CLI
Usage: cba-netbank <command> [args]

Commands:
  list      List accounts
  download  Download transactions history for given account
  ui        Interactive user interface.

Options:
  -u, --username  client number [string] [required] [default: $NETBANK_USERNAME]
  -p, --password  password      [string] [required] [default: $NETBANK_PASSWORD]
  --help          Show help                                            [boolean]

There are 3 commands, list, download and ui.

Username and password can be given via the arguments, --username and --password, as well as the environment variables, NETBANK_USERNAME and NETBANK_PASSWORD.

You can use list command to see the account list, and use download command to download the transaction history in given format, there are more arguments for download command:

$ cba-netbank download --help
cba-netbank download

Options:
  -u, --username  client number [string] [required] [default: $NETBANK_USERNAME]
  -p, --password  password      [string] [required] [default: $NETBANK_PASSWORD]
  --help          Show help                                            [boolean]
  -a, --account   account name or number                     [string] [required]
  -f, --from      history range from date       [string] [default: "03/04/2017"]
  -t, --to        history range to date         [string] [default: "03/07/2017"]
  -o, --output    output file name
                 [string] [default: "[<name>](<number>) [<from> to <to>].<ext>"]
  --format        the output file format
  [string] [choices: "json", "csv", "qif", "aus.qif", "us.qif", "ofx"] [default:
                                                                         "json"]

You can use -a to specify which account you want to download the history from, and the value can be part of the name or account number. For example, if the account name you want to specified is Smart Access, then you can use -a smart to save some time.

Currently, JSON, CSV, QIF and OFX format is supported for the transactions history export format.

About the QIF format, there are several options:

  • qif is most common one, which is for QIF(MYOB, MSMoney, or Quicken 2005 or later);
  • aus.qif is for some old software, such as QIF (Quicken AUS 2004 or earlier);
  • us.qif is for some old software, such as QIF (Quicken US 2004 or earlier).

Interactive UI

This is an UI you can just use <UP> and <DOWN> key to list accounts and its recent transactions.

$ cba-netbank ui
Logon as account 1234567 ...
? Which account?
โฏ Smart Access 	(062001 12340001)	 Balance: $987.65 	 Available Funds: $907.65
  NetBank Saver 	(062002 12340012)	 Balance: $4321.01 	 Available Funds: $4021.00
  GoalSaver 	(062003 12340013)	 Balance: $32109.87 	 Available Funds: $32109.87
  Complete Access 	(062004 12340014)	 Balance: $1234.56 	 Available Funds: $1023.45
  MasterCard Platinum 	( 5520123456789012)	 Balance: $-1234.56 	 Available Funds: $12345.67
  <Quit>

Use <UP> and <DOWN> key to select an account then press <ENTER>, the recent transaction history will be downloaded and shown below.

Downloading history [03/05/2017 => 03/07/2017] ...
Time              Description                                                                     Amount    Balance
----------------  ------------------------------------------------------------------------------  --------  --------
2017-07-01 00:00  PENDING - HURSTSVILLE TONGLI S   HURSTVILLE , 0701; LAST 4 CARD DIGITS 4341     $-3.09
2017-07-01 00:00  PENDING - DAMS APPLE AT THE STAT HURSTVILLE , 0701; LAST 4 CARD DIGITS 4341     $-12.37
...
2017-07-01 04:39  THE NAKED DUCK DARLING SYDNEY NS AUS; Card xx4341; Value Date: 28/06/2017       $-13.50   $909.66
2017-07-01 04:39  TOPSHOP TOPMAN SYDNE SYDNEY  AUS; Card xx4341; Value Date: 30/06/2017           $-80.00   $927.16
...
2017-06-12 16:13  Cardless Cash for collection                                                    $-40.00   $1111.83

Total 69 transactions and 12 pending transactions.

To quit the CLI, just select <Quit> then press <Enter>.

Library

Install

npm install node-cba-netbank --save

List Accounts

API: netbank.logon(username, password)

  • username: the netbank client number;
  • password: the netbank password;

Returned object will contains an accounts field, which contains all the account information.

Example of list accounts

const Netbank = require('node-cba-netbank');

const netbank = new Netbank();

netbank.logon('76543210', 'YOUR_PASSWORD')
  .then(resp => {
    //  output account to console
    resp.accounts.forEach(
      a => console.log(`${a.name} (${a.bsb} ${a.account}) => ${a.balance}/${a.available}`)
    );
  })
  .catch(console.error);

Just replace 76543210 with your client number, and replace YOUR_PASSWORD with your netbank password.

The result will look like below:

Smart Access (062001 12340001) => 987.65/907.65
NetBank Saver (062002 12340012) => 4321.01/4021.00
...

For each account, there are following properties:

  • name: Account name;
  • url: Transaction page for the account, it will be different everytime you logged in;
  • bsb: BSB number;
  • account: Account number (without BSB part);
  • number: The entire account number, bsb+account, without space;
  • balance: Current account balance. It might be different from the available funds;
  • available: Current available funds of the account.

Retrieve Transactions for Given Account

API: netbank.getTransactionHistory(account, from, to)

  • account: one of the account object retrieved from the previous .logon() api
  • from: the begin date of the search period. format is DD/MM/YYYY, [default: 6 years ago (bank may not store transactions for such long time.)]
  • to: the end date of the search period. format is DD/MM/YYYY, [default: today]

The returned object will contains following field:

  • transactions: the processed transactions;
  • pendings: the pending transactions;

Example of retrieve transactions

const Netbank = require('node-cba-netbank');

const netbank = new Netbank();

netbank.logon('76543210', 'YOUR_PASSWORD')
  // Assume we are going to retrieve the transactions of the first account, from '1/1/2017' to today
  .then(resp => netbank.getTransactionHistory(resp.accounts[0], '1/1/2017'))
  .then((resp) => {
    //  output transactions to console
    resp.transactions.forEach(t => console.log(`${t.date} ${t.description} => ${t.amount}`));
  })
  .catch(console.error);

Be aware, it might take several minutes if there are thousands transactions.

The transaction list will look like below:

2015-04-20T00:00:00.004Z SO THAI RESTAURANT       KOGARAH => -13.9
2015-04-20T00:00:00.003Z NOK NOK                  SYDNEY => -41.8
...

For each transaction object, there are following properties:

  • timestamp: Timestamp of given transaction, it's milliseconds since epoch. Although, it might be pretty accurate for some accounts (non-credit card account), it might just be accurate at date level;
  • date: It's human readable date format;
  • description: Transaction description;
  • amount: Transaction amount, negative value is DR, positive value is CR;
  • balance: The balance of the account after the transaction happened, however, the field might be empty for some accounts, such as credit card account;
  • trancode: It's a category code for the transaction, such as ATM, EFTPOS, cash out might be different code;
  • receiptnumber: The receipt number for the transaction. However, I cannot found it on my real paper receipt, and the field might be missing for some accounts, such as credit card account;

Testing

Offline test can be done by simply run yarn test.

To enable real world testing, please set environment variables NETBANK_USERNAME and NETBANK_PASSWORD to your client number and password for online banking.

Then run command:

yarn test

to have more details, you can run yarn test-debug for more verbose output.

The test will try to login and get transactions from the first account, and if it will fail if the retrieved transactions number is less than 400. It's ok if you don't have that much transactions in the account. The purpose of checking whether it get more than 400 transactions is to check whether it can overcome the maximum transactions limits.

node-cba-netbank's People

Contributors

grassdog avatar twang2218 avatar wongio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-cba-netbank's Issues

error during install " Error: not found: make" (ubuntu 16.04)

Weirdly enough first time I installed this package (ubuntu) as per the instructions, things worked easily.

second time around (fresh install of ubuntu), this error
" Error: not found: make"

fix turned out to be easy.

sudo apt-get install build-essential
npm install node-cba-netbank --save

hope it helps someone.

really nice package btw. thanks for publishing.

Can't pull transactions from multiple accounts

For some reason when calling getTransactions twice it fails to download and parse the transactions in the first request. I get the error "Cannot find transaction section". When it's called on its own it works perfectly fine.

Ultimately what I want to be able to to do is:
for ( var i = 0; i < accounts.length; i++ ){
netbank.getTransactions(accounts[i]), callback);
}

Any ideas?

netbank.getTransactions(accounts[0], function (error, transactions) {
if (error === null) {

     console.log(transactions);
   } else {
     console.error(error);
   }
 });
  netbank.getTransactions(accounts[1], function (error, transactions) {
   if (error === null) {

     console.log(transactions);
   } else {
     console.error(error);
   }
 });

Fails on pulling transactions

Fails on pulling transactions (moreAgain) line 174 in app.js

function (error, url, moreAgain)

I think it should be (error, moreAgain)

moreAgain is undefined in the next if statement moreAgain.length

Failed to logged in, try again?

I can login using the same credential on web netbank and mobile app.

#  cba-netbank ui
Logon as account 1xxxxxxx ...
? Failed to logged in, try again? No

I have tried export NETBANK_USERNAME=xxx, -u argument and entering details manually.

Function Missing Logon

screen shot 2017-07-11 at 6 10 34 am

When using the readme code, the logon function appears to not be working on the latest build.

Not returning transactions

Hi, the script doesn't return any of the transactions. (The list of accounts works great.)

parseTransactions is rejected with the message 'Cannot find transactions in the resp'

I have had a look at the html file that is returned in the log folder. It doesn't have any of the transaction data within it, and if I open the static page in a browser it just shows the spinners.

Please let me know if I can help trouble shoot in any way

Fails for certain account type

Hi, love this project!

The parseAccountList function is failing if the account list includes Commsec Shares.

Commsec Shares can appear in the account list, but do not contain any balance information and just functions as a convenient way to click onto your commsec portfolio on the commsec website.

This line is failing: type: ${/ACCOUNT_PRODUCT_TYPE=(\w+)/.exec(acc.link)[1]}
TypeError: Cannot read property '1' of null

As an example of the data for this type of account,
acc.link = "/netbank/usermaintenance/CommSecLauncher.aspx?XXXXXXXXETC,ETC"
acc.name="CommSec Shares"

I think it would be best to filter and not include this account type in the accountRows.each function - doesn't seem any point including it since no information is provided on the account screen (not even the balance).

The code below fixes the problem - you may want a more elegant way though?

if ($$('.NicknameField .left a').text().trim() != "CommSec Shares")
{
accounts.push({
name: $$('.NicknameField .left a').text().trim(),
link: $$('.NicknameField .left a').attr('href'),
bsb: $$('.BSBField .text').text().replace(/\s+/g, '').trim(),
account: $$('.AccountNumberField .text').text().replace(/\s+/g, '').trim(),
balance: parseCurrencyHtml($$('.AccountBalanceField')),
available: parseCurrencyHtml($$('.AvailableFundsField'))
});

Retrieve Category with Transactions?

Would it be possible to grab the Category along with the other transaction details?

Date, Transaction details, Category, Amount, Total

This would be very useful for stacked column graphs of expenses via Category.

Most recent transactions not appearing

Hi, thanks so much for making this available - it's great!

I've noticed the most recent transactions aren't being pulled. As I try this at around 11pm AEST, only transactions up to the previous day are being returned, not today's transactions.

Perhaps this line is the issue? Should it be a reference to local time rather than UTC?

var to = toDateString(moment.utc().valueOf());

Can't retrieve pending transactions from api.js

It looks like they should be accessible via resp.pendings.forEach(t... but I keep getting the following error: Cannot read property 'forEach' of undefined

resp.transactions works fine.

I only want to see Pending transactions for the current day.

Broken with last CBA update

The login process is now broken. Hopefully it's just the login to fix, and the rest of the functionality still works!

Transaction download is failing for a Complete Access account

Downloading seems to have stopped working for one of my accounts in the last week or so.

When I try to download from a Complete Access account using the debug build I see the following:

Downloading history [15/11/2017 => 15/02/2018] ...
  node-cba-netbank getTransactionHistory(account: Complete Access [XXXXX] => 90.92) +0ms
  node-cba-netbank GET https://www2.my.commbank.com.au/netbank/TransactionHistory/History.aspx?ACCOUNT_... +1ms
  node-cba-netbank headers => {} +0ms
  node-cba-netbank parseTitle(): found title => 'Transactions' +1s
Unhandled rejection Cannot find transactions in the resp

Other accounts still seem to work fine.

I'll try to debug what's going on but I'm guessing you'd be able to see what's happening more quickly ๐Ÿ˜„

Can't download transaction history

Hello guys,

thank you for this awesome netbank interface!
I installed it on my laptop and tried the download cli option but it returned with an error:
Unhandled rejection Error: Cannot find transactions in the resp
at /home/tamas/.nvm/versions/node/v8.11.2/lib/node_modules/node-cba-netbank/dist/parser.js:262:19

This is how I used it:
cba-netbank -u PPPPPPP -p FFFFFFFF download -a 'XXXXXX'

I have logged the downloaded response and opened in a browser and I can see the transaction history page with the spinners circling and no transactions displayed.

Can't see the transactions when using the ui option either. After selecting the account the program prints bye and exits.

Let me know if I'm doing something wrong.

Cheers
Tamas

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.