UNPKG

n8n-nodes-smartsuite

Version:
65 lines 2.72 kB
"use strict"; // src/nodes/SmartSuite/actions/api/makeApiRequest.operation.ts Object.defineProperty(exports, "__esModule", { value: true }); exports.executeMakeApiRequest = executeMakeApiRequest; const n8n_workflow_1 = require("n8n-workflow"); const smartSuiteApi_1 = require("../../transport/smartSuiteApi"); async function executeMakeApiRequest(index) { try { // 1) HTTP method comes from the "operation" dropdown now const method = this.getNodeParameter('operation', index); const url = this.getNodeParameter('url', index); // 2) Build `qs` let qs = {}; if (this.getNodeParameter('sendQuery', index)) { if (this.getNodeParameter('specifyQuery', index) === 'fields') { const items = this.getNodeParameter('queryParameters.parameter', index, []); items.forEach(({ name, value }) => { if (name) qs[name] = value; }); } else { qs = this.getNodeParameter('jsonQuery', index); } } // 3) Build `headers` let headers = {}; if (this.getNodeParameter('sendHeaders', index)) { if (this.getNodeParameter('specifyHeaders', index) === 'fields') { const items = this.getNodeParameter('headerParameters.parameter', index, []); items.forEach(({ name, value }) => { if (name) headers[name] = value; }); } else { headers = this.getNodeParameter('jsonHeaders', index); } } // 4) Build `body` let body = {}; if (this.getNodeParameter('sendBody', index)) { if (this.getNodeParameter('specifyBody', index) === 'fields') { const items = this.getNodeParameter('bodyParameters.parameter', index, []); items.forEach(({ name, value }) => { if (name) body[name] = value; }); } else { body = this.getNodeParameter('jsonBody', index); } } // 5) Delegate to generic helper const response = await smartSuiteApi_1.apiRequest.call(this, method, url, body, qs, headers); // 6) Return JSON array return this.helpers.returnJsonArray(Array.isArray(response) ? response : [response]); } catch (error) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), error); } } // for compatibility, also export as default exports.default = executeMakeApiRequest; //# sourceMappingURL=makeApiRequest.operation.js.map