zonky-api-handler
v2.35.46
Published
Unofficial handler for Zonky API
Downloads
8
Readme
Zonky API handler
Unofficial API handler for Zonky. You can see full documentation on apiary.
How to use
Install package:
npm install zonky-api-handler
You must include polyfill for browser fetch to use it with Node.
require('cross-fetch/polyfill');
const { DateTime } = require('luxon');
const { ZonkyApi } = require('zonky-api-handler');
(async () => {
const api = new ZonkyApi();
await api.login(USERNAME, PASSWORD);
const { transactions } = await api.getTransactions(DateTime.fromISO('2018-01-01'));
console.log(transactions);
})()
You can also request export token and download xlsx reports:
require('cross-fetch/polyfill');
const fs = require('fs');
const { ZonkyApi } = require('zonky-api-handler');
(async () => {
const api = new ZonkyApi();
await api.login(USERNAME, PASSWORD);
const investments = await api.downloadInvestments();
fs.writeFileSync('investments.xlsx', investments);
})()
Downloading of transactions.
To download transactions you need to authorize through the SMS code. Example with Vorpal CLI:
require('cross-fetch/polyfill');
const vorpal = require('vorpal')();
const { ZonkyApi, EXCEPTION } = require('zonky-api-handler');
const USERNAME = 'XXX';
const PASSWORD = 'XXX';
const api = new ZonkyApi();
vorpal.command('download', 'Download transaction report.')
.action(async function (args, cb) {
// login user
await api.login(USERNAME, PASSWORD);
// send request to download transaction
try {
await api.downloadTransactions();
} catch (exception) {
// if the error is SMS required, continue, otherwise show an error
if (!(exception instanceof EXCEPTION.ZonkyApiSMSException)) {
throw exception;
}
console.log('SMS code was sent to your phone.');
}
// request SMS code from user
const { sms } = await this.prompt([
{
type: 'input',
name: 'sms',
message: 'SMS code: ',
},
]);
// download file with the SMS code
const data = await api.downloadTransactions(sms);
// print output
console.log(data);
cb();
});
vorpal
.show()
.parse(process.argv);
CLI to download Zonky reports
usage: zonky-report-download [email protected] password-zonky transactions.xlsx investments.xlsx
require('cross-fetch/polyfill');
const fs = require('fs');
const { ZonkyApi } = require('zonky-api-handler');
(async () => {
if (process.argv.length!=6) {
console.log("zonky-report-download <login-email> <zonky-password> <transaction filename> <investments filename>");
console.log("zonky-report-download [email protected] password-zonky transactions.xlsx investments.xlsx");
process.exit(-1);
}
const api = new ZonkyApi();
console.log(`Login to Zonky: ${process.argv[2]}`);
await api.login(process.argv[2], process.argv[3]);
console.log(`Download transactions: ${process.argv[4]}`);
const transactions = await api.downloadTransactions();
fs.writeFileSync(process.argv[4], transactions);
console.log(`Download investments: ${process.argv[5]}`);
const people = await api.downloadInvestments();
fs.writeFileSync(process.argv[5], people);
console.log("Done");
})()