n8n-nodes-ynab
Version:
A YNAB integration for n8n
85 lines • 3.61 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.UpdateTransactions = void 0;
const n8n_workflow_1 = require("n8n-workflow");
class UpdateTransactions {
constructor() {
this.description = {
displayName: 'YNAB - Update Transactions',
name: 'updateTransactions',
group: ['transform'],
version: 1,
description: 'YNAB Update Transactions',
icon: 'file:icons/ynab.svg',
defaults: {
name: 'Update 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: 'Body',
name: 'body',
type: 'json',
default: '{}',
placeholder: '{}',
description: 'A JSON object. The object should have all the values to update. ' +
'The transactions to update. Each transaction must have either an ID or import_id specified. ' +
'If id is specified as null an import_id value can be provided which will allow transaction(s) ' +
'to be updated by its import_id. If an id is specified, it will always be used for lookup. ' +
'You should not specify both id and import_id. Updating an import_id on an existing transaction ' +
'is not allowed; if an import_id is specified, it will only be used to lookup the transaction.',
},
],
};
}
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.UpdateTransactions = UpdateTransactions;
//# sourceMappingURL=UpdateTransactions.node.js.map