UNPKG

@blotato/n8n-nodes-blotato

Version:
59 lines 2.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAccounts = getAccounts; exports.getSubaccounts = getSubaccounts; async function getAccounts() { const platform = this.getNodeParameter('platform', 0); const options = {}; options.qs = { platform }; options.method = `GET`; const credentials = await this.getCredentials('blotatoApi'); options.uri = credentials.server + '/v2/users/me/accounts'; const responseData = await this.helpers.requestWithAuthentication.call(this, 'blotatoApi', options); const results = JSON.parse(responseData).items.map((item) => ({ name: item.fullname || item.username, value: item.id, url: `${credentials.server}/v2/accounts/${item.id}`, })); return { results }; } async function getSubaccounts() { const platform = this.getNodeParameter('platform', 0); try { const accountIdParam = this.getNodeParameter('accountId', 0); const accountId = typeof accountIdParam === 'object' ? accountIdParam.value : accountIdParam; if (!accountId) { return { results: [ { name: 'Please select an account above first', value: '', }, ], }; } const options = {}; options.qs = { platform }; options.method = `GET`; const credentials = await this.getCredentials('blotatoApi'); options.uri = credentials.server + `/v2/users/me/accounts/${accountId}/subaccounts`; const responseData = await this.helpers.requestWithAuthentication.call(this, 'blotatoApi', options); const results = JSON.parse(responseData).items.map((item) => ({ name: item.name, value: item.id, url: `${credentials.server}/v2/accounts/${item.accountId}/subaccounts/${item.id}`, })); return { results }; } catch (error) { return { results: [ { name: 'Please select an account above first', value: '', }, ], }; } } //# sourceMappingURL=SearchFunctions.js.map