UNPKG

n8n-nodes-ynab

Version:
88 lines 3.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GetTransactions = void 0; const n8n_workflow_1 = require("n8n-workflow"); class GetTransactions { constructor() { this.description = { displayName: 'YNAB - Get Transactions', name: 'getTransactions', group: ['transform'], version: 1, description: 'YNAB Get Transactions', icon: 'file:icons/ynab.svg', defaults: { name: 'Get Transactions', }, inputs: ['main'], outputs: ['main'], credentials: [ { name: 'ynabApi', required: true, }, ], properties: [ { displayName: 'Budget ID', name: 'budget_id', type: 'string', default: '', placeholder: '6906942e-b16e-4158-bfaa-b7a7d520e221', description: 'Budget identifier. Check your budgets to find the correct value.', }, { displayName: 'Type', name: 'type', type: 'string', default: '', placeholder: 'uncategorized', description: 'If specified, only transactions of the specified type will be included. The value should be uncategorized or unapproved.', }, { displayName: 'Since Date', name: 'sinceDate', type: 'string', default: '', placeholder: '2024-12-30', description: 'If specified, only transactions on or after this date will be included. The date should be ISO formatted (e.g. 2016-12-30).', }, ], }; } async execute() { const returnData = []; const items = this.getInputData(); for (let itemIndex = 0; itemIndex < items.length; itemIndex++) { const budgetId = this.getNodeParameter('budget_id', itemIndex, ''); const type = this.getNodeParameter('type', itemIndex, ''); const sinceDate = this.getNodeParameter('sinceDate', itemIndex, ''); const queryParams = new URLSearchParams(); if (type) { queryParams.append('type', type); } if (sinceDate) { queryParams.append('since_date', sinceDate); } const baseUrl = `https://api.ynab.com/v1/budgets/${budgetId}/transactions`; const queryString = queryParams.toString(); const options = { method: 'GET', url: queryString ? `${baseUrl}?${queryString}` : baseUrl, json: true, }; try { const response = await this.helpers.httpRequestWithAuthentication.call(this, 'ynabApi', options); returnData.push({ json: { response }, }); } catch (error) { throw new n8n_workflow_1.NodeApiError(this.getNode(), error); } } return [returnData]; } } exports.GetTransactions = GetTransactions; //# sourceMappingURL=GetTransactions.node.js.map