euforic / banking.js

The Missing API for Banks - Get all of your transactions and balances using node

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OFX parsing breaks with OFX files from my bank

steveharrison opened this issue · comments

Hey, I'm trying to use Banking JS to parse OFX data from my bank, but I'm getting the following error:

/path-to-nodejs-project/app.js:177
    var CCSTMTTRNRS = res.body.OFX.CREDITCARDMSGSRSV1.CCSTMTTRNRS;
                              ^

TypeError: Cannot read property 'OFX' of undefined
    at /path-to-nodejs-project/app.js:177:31
    at /path-to-nodejs-project/node_modules/banking/lib/banking.js:70:7
    at Object.OFX.parse (/path-to-nodejs-project/node_modules/banking/lib/ofx.js:173:3)
    at path-to-nodejs-project/node_modules/banking/lib/banking.js:69:9
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)
Steve-2:path-to-nodejs-project steveharrison$ 

It works fine with OFX files from other credit card providers, but fails for any OFX files from my bank.

This is an OFX file that breaks (modified to remove personal info):

OFXHEADER:100
DATA:OFXSGML
VERSION:102
SECURITY:NONE
ENCODING:USASCII
CHARSET:1252
COMPRESSION:NONE
OLDFILEUID:NONE
NEWFILEUID:NONE
<OFX>
<SIGNONMSGSRSV1>
<SONRS>
<STATUS>
<CODE>0
<SEVERITY>INFO
</STATUS>
<DTSERVER>20170844045844
<LANGUAGE>ENG
</SONRS>
</SIGNONMSGSRSV1>
<CREDITCARDMSGSRSV1>
<CCSTMTTRNRS>
<TRNUID>1
<STATUS>
<CODE>0
<SEVERITY>INFO
</STATUS>
<CCSTMTRS>
<CURDEF>AUD
<CCACCTFROM>
<ACCTID>1234567890123456
</CCACCTFROM>
<BANKTRANLIST>
<DTSTART>20150808000000
<DTEND>20170808000000
<STMTTRN>
<TRNTYPE>CREDIT
<DTPOSTED>20170701
<DTUSER>201700701
<TRNAMT>63.10
<FITID>A123456789012
<MEMO>RECEIVED PAYMENT            
</STMTTRN>
<STMTTRN>
<TRNTYPE>CREDIT
<DTPOSTED>20170702
<DTUSER>20170702
<TRNAMT>39.00
<FITID>A821582159120
<MEMO>RECEIVED PAYMENT            
</STMTTRN>
<STMTTRN>
<TRNTYPE>DEBIT
<DTPOSTED>20170801
<DTUSER>20170801
<TRNAMT>-20.50
<FITID>
<MEMO>MERCHANT NAME, LOCATION  
</STMTTRN>
</BANKTRANLIST>
<LEDGERBAL>
<BALAMT>-1234.00
<DTASOF>20170844045844
</LEDGERBAL>
<AVAILBAL>
<BALAMT>1234.00
<DTASOF>20170844045844
</AVAILBAL>
</CCSTMTRS>
</CCSTMTTRNRS>
</CREDITCARDMSGSRSV1>
</OFX>

Any ideas?

probably isn't valid OFX there is usually a newline between the header and the body