zonky-api-handler
TypeScript icon, indicating that this package has built-in type declarations

2.35.46 • Public • Published

Zonky API handler

npm version renovate-app Known Vulnerabilities codecov travis

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 login@email.abc 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 login@email.abc 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");
})()

Readme

Keywords

none

Package Sidebar

Install

npm i zonky-api-handler

Weekly Downloads

2

Version

2.35.46

License

Apache-2.0

Unpacked Size

86 kB

Total Files

55

Last publish

Collaborators

  • fabulator