n8n-nodes-ynab
Version:
A YNAB integration for n8n
67 lines • 2.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetCategories = void 0;
class GetCategories {
constructor() {
this.description = {
displayName: 'YNAB - Get Categories',
name: 'getCategories',
group: ['transform'],
version: 1,
description: 'YNAB Get Categories',
defaults: {
name: 'Get Categories',
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'ynabApi',
required: true,
},
],
properties: [
{
displayName: 'Budget ID',
name: 'budget_id',
type: 'string',
default: '',
placeholder: 'Placeholder value',
description: 'Budget identifier. Check your budgets to find the correct value.',
},
],
};
}
async execute() {
const returnData = [];
const apiKey = await this.getCredentials('ynabApi');
const items = this.getInputData();
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
const budgetId = this.getNodeParameter('budget_id', itemIndex, '');
const options = {
method: 'GET',
url: `https://api.ynab.com/v1/budgets/${budgetId}/categories`,
headers: {
Authorization: `${apiKey.token ? `Bearer ${apiKey.token}` : ''}`,
'Content-Type': 'application/json',
},
json: true,
};
try {
const response = this.helpers.request(options);
returnData.push({
json: { response },
});
}
catch (error) {
if (error instanceof Error) {
throw Error(`Error getting budgets: ${error.message}`);
}
throw error;
}
}
return [returnData];
}
}
exports.GetCategories = GetCategories;
//# sourceMappingURL=GetCategories.node.js.map