Skip to content

Instantly share code, notes, and snippets.

@Sanchiz
Forked from userhooke/monobank-ynab.js
Created November 12, 2020 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sanchiz/99528c563e03d8bca16c397b9d942799 to your computer and use it in GitHub Desktop.
Save Sanchiz/99528c563e03d8bca16c397b9d942799 to your computer and use it in GitHub Desktop.
Serverless script to link Monobank API and YNAB
const ynab = require("ynab");
const ynabAPI = new ynab.API(process.env.YNAB_TOKEN);
const adMaioraBudgetId = process.env.BUDGET_ID;
const monoDebitAccountId = process.env.MONO_DEBIT_ACCOUNT_ID;
module.exports.handler = (event, context, callback) => {
const body = JSON.parse(event.body);
console.log('Event body: ', body);
if (!body || !body.data || !body.data.statementItem) {
callback(null, {
statusCode: 400,
headers: {},
body: JSON.stringify({error: "No data provided :("})
});
}
callback(null, {
statusCode: 200,
headers: {},
body: JSON.stringify({status: 'Ok!'})
});
ynabAPI.transactions
.createTransaction(adMaioraBudgetId, {
transaction: {
account_id: monoDebitAccountId,
date: ynab.utils.getCurrentDateInISOFormat(),
amount: body.data.statementItem.amount + "0",
payee_name: body.data.statementItem.description
}
})
.then(res => {
console.log('YNAB Response: ', res);
})
.catch(err => {
console.error('YNAB error: ', err);
});
};
@mrmauadi
Copy link

monobank-ynab.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment