UNPKG

n8n-nodes-base

Version:

Base nodes of n8n

47 lines 1.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.zulipApiRequest = zulipApiRequest; exports.validateJSON = validateJSON; const n8n_workflow_1 = require("n8n-workflow"); async function zulipApiRequest(method, resource, body = {}, query = {}, uri, option = {}) { const credentials = await this.getCredentials('zulipApi'); const endpoint = `${credentials.url.toString().replace(new RegExp('/$'), '')}/api/v1`; let options = { auth: { user: credentials.email, password: credentials.apiKey, }, headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, method, form: body, qs: query, uri: uri || `${endpoint}${resource}`, json: true, }; if (!Object.keys(body).length) { delete options.form; } if (!Object.keys(query).length) { delete options.qs; } options = Object.assign({}, options, option); try { return await this.helpers.request(options); } catch (error) { throw new n8n_workflow_1.NodeApiError(this.getNode(), error); } } function validateJSON(json) { let result; try { result = JSON.parse(json); } catch (exception) { result = undefined; } return result; } //# sourceMappingURL=GenericFunctions.js.map