UNPKG

n8n-nodes-chatwork

Version:

Provides n8n nodes to retrieve data from Chatwork API.

35 lines (34 loc) 1.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.chatworkApiRequest = void 0; const Constants_1 = require("./Constants"); async function chatworkApiRequest(method, endpoint, body) { const options = { method, headers: { 'User-Agent': 'n8n', }, uri: '', json: true, }; try { const credentials = await this.getCredentials(Constants_1.CREDENTIAL.TYPE); options.uri = `${Constants_1.BASE_URL}${endpoint}`; options.headers['X-ChatWorkToken'] = credentials[Constants_1.CREDENTIAL.PROPERTY_NAME]; if (body) { options.form = body; } return await this.helpers.request(options); } catch (error) { const httpError = error; if (httpError.statusCode === 401) { throw new Error('The Chatwork credentials are not valid!'); } if (httpError.response && httpError.response.body && httpError.response.body.message) { throw new Error(`Chatwork error response [${httpError.statusCode}]: ${httpError.response.body.message}`); } throw error; } } exports.chatworkApiRequest = chatworkApiRequest;