Created
February 3, 2020 11:16
-
-
Save userhooke/51f0160fdebeb0bab3a3a159acdff9d5 to your computer and use it in GitHub Desktop.
Revisions
-
Vladimir Hooke created this gist
Feb 3, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ 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); }); };