-
-
Save Sanchiz/99528c563e03d8bca16c397b9d942799 to your computer and use it in GitHub Desktop.
Serverless script to link Monobank API and YNAB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
monobank-ynab.js