API to load OFX
After five years of waiting, I've finally given up on native integration between YNAB and my bank and am trying to roll my own. My Bank, Kiwibank, is not in North America so who knows when or if it will ever be supported.
I've successfully written a small Python script which downloads the transactions from my bank into a couple OFX files. My problem is uploading these into YNAB. I've tried two methods, writing a robot and using the API.
Method 1: Robot
Using much the same method as I used to download the file, I was able to log into YNAB, navigate to import file, etc. It seems to work but I keep having random trouble with the login page, about half the time I hit login and nothing happens.
I strongly suspect I'm running into an anti-robot issue. YNAB is using some software to detect and prevent bots logging in. I've tried working around it but ... I'm not a fan of hacking around security.
Method 2: API
I was able to find a OFX library for Python (ofxtools). However it says the OFX I've downloaded from my bank is invalid. For my savings account I get the error message: "Elements out of order: According to the class spec for SONRS, STATUS should occur before DTSERVER" and for my CC I get the error message: "Can't set SONRS.status to None: SubAggregate: Value is required".
- Is there a way to make my robot robust? Maybe get my IP whitelisted? I tried clicking on 'remember password' but Selenium seems to start in essentially incognito mode.
- Clearly the GUI version of YNAB can handle the OFX files from my bank. Is it possible to call whatever API that uses rather than try and parse the OFX in Python and upload that way.
- Is there another way? E.g. download a QIF from my mac, or a different OFX to YNAB uploader
I'm in the same situation and got it to work with CSVs (it's the only format my bank offers). It's a much simpler format than OFX, so there is less room for the banks to mess up and it's easier to clean up the mess (e.g. my bank adds separators at the end of each line, which I can remove quite easily).
Thread is here: https://support.youneedabudget.com/t/x2hzbtb/csv-import-via-api
As Blue Wizard says,
If you can get the transactions in CSV format, it would be simpler to transform the CSV format to a payload for the API.
Another tings comes to mind...
Looking at the ofxtools documentation, have you tried using ofxget to get your transactions?
Maybe that will create an OFX file that ofxtools can work with?