UNPKG

n8n-nodes-zoho

Version:
219 lines 8.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ZohoSheets = void 0; const n8n_workflow_1 = require("n8n-workflow"); const GenericFunctions_1 = require("./GenericFunctions"); class ZohoSheets { constructor() { this.description = { displayName: 'Zoho Sheets', name: 'zohoSheets', icon: 'file:zoho.svg', group: ['transform'], version: 1, subtitle: '={{$parameter["operation"]}}', description: 'Consume Zoho Sheet API', defaults: { name: 'Zoho Sheet', }, inputs: ["main"], outputs: ["main"], credentials: [ { name: 'zohoApi', required: true, }, ], properties: [ { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, options: [ { name: 'Create Workbook', value: 'create', }, { name: 'List Workbooks', value: 'list', }, { name: 'Add Records to Worksheet', value: 'addRecords', }, ], default: 'create', }, { displayName: 'Workbook Name', name: 'workbookName', type: 'string', default: '', required: true, displayOptions: { show: { operation: ['create'], }, }, description: 'Name of the workbook to create', }, { displayName: 'Start Index', name: 'startIndex', type: 'number', default: 1, displayOptions: { show: { operation: ['list'], }, }, description: 'Start index for pagination', }, { displayName: 'Count', name: 'count', type: 'number', default: 1000, displayOptions: { show: { operation: ['list'], }, }, description: 'Number of records to return', }, { displayName: 'Sort Option', name: 'sortOption', type: 'string', default: '', displayOptions: { show: { operation: ['list'], }, }, description: 'Sort option (e.g. recently_modified)', }, { displayName: 'Workbook Resource ID', name: 'resourceId', type: 'string', default: '', required: true, displayOptions: { show: { operation: ['addRecords'], }, }, description: 'ID of the workbook to modify', }, { displayName: 'Worksheet Name', name: 'worksheetName', type: 'string', default: '', displayOptions: { show: { operation: ['addRecords'], }, }, description: 'Name of the worksheet to add records to (required if worksheetId not set)', }, { displayName: 'Worksheet ID', name: 'worksheetId', type: 'string', default: '', displayOptions: { show: { operation: ['addRecords'], }, }, description: 'ID of the worksheet to add records to (required if worksheetName not set)', }, { displayName: 'Header Row', name: 'headerRow', type: 'number', default: 1, displayOptions: { show: { operation: ['addRecords'], }, }, description: 'Header row index (default is 1)', }, { displayName: 'JSON Data', name: 'jsonData', type: 'string', default: '', required: true, displayOptions: { show: { operation: ['addRecords'], }, }, description: 'JSON array string of records to add', }, ], }; } async execute() { const items = this.getInputData(); const returnData = []; const operation = this.getNodeParameter('operation', 0); const baseURL = 'https://sheet.zoho.eu/api/v2'; for (let i = 0; i < items.length; i++) { if (operation === 'create') { const workbookName = this.getNodeParameter('workbookName', i); const qs = { method: 'workbook.create', workbook_name: workbookName, }; const responseData = await GenericFunctions_1.zohoApiRequest.call(this, 'POST', baseURL, '/create', null, qs); returnData.push({ json: JSON.parse(responseData) }); } else if (operation === 'list') { const sortOption = this.getNodeParameter('sortOption', i); const qs = { method: 'workbook.list', start_index: this.getNodeParameter('startIndex', i) || 1, count: this.getNodeParameter('count', i) || 1000 }; if (sortOption) { qs.sort_option = sortOption; } const responseData = await GenericFunctions_1.zohoApiRequest.call(this, 'POST', baseURL, '/workbooks', null, qs); returnData.push({ json: JSON.parse(responseData) }); } else if (operation === 'addRecords') { const resourceId = this.getNodeParameter('resourceId', i); const worksheetName = this.getNodeParameter('worksheetName', i); const worksheetId = this.getNodeParameter('worksheetId', i); const headerRow = this.getNodeParameter('headerRow', i); const jsonData = this.getNodeParameter('jsonData', i); if (!worksheetName && !worksheetId) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Please specify either worksheetName or worksheetId'); } const qs = { method: 'worksheet.records.add', json_data: jsonData, header_row: headerRow, }; if (worksheetName) { qs.worksheet_name = worksheetName; } else { qs.worksheet_id = worksheetId; } const responseData = await GenericFunctions_1.zohoApiRequest.call(this, 'POST', baseURL, `/${resourceId}`, null, qs); returnData.push({ json: JSON.parse(responseData) }); } } return [this.helpers.returnJsonArray(returnData)]; } } exports.ZohoSheets = ZohoSheets; //# sourceMappingURL=ZohoSheets.node.js.map