n8n-nodes-clint
Version:
Custom Clint CRM nodes for n8n
76 lines (75 loc) • 2.7 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ClintSupport = void 0;
const axios_1 = __importDefault(require("axios"));
class ClintSupport {
constructor() {
this.description = {
displayName: 'Clint Support Info',
name: 'clintSupport',
group: ['transform'],
version: 1,
description: 'Leitura de grupos, status, tags, usuários e campos da API Clint',
defaults: {
name: 'Clint Support Info',
color: '#888888',
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'clintApi',
required: true,
},
],
properties: [
{
displayName: 'Endpoint',
name: 'endpoint',
type: 'options',
options: [
{ name: 'Groups', value: 'groups' },
{ name: 'Users', value: 'users' },
{ name: 'Tags', value: 'tags' },
{ name: 'Origins', value: 'origins' },
{ name: 'Lost Status', value: 'lost-status' },
{ name: 'Fields', value: 'account/fields' },
],
default: 'groups',
},
],
};
}
async execute() {
var _a;
const items = this.getInputData();
const returnData = [];
const credentials = await this.getCredentials('clintApi');
const token = credentials.apiToken;
const headers = {
Authorization: `Bearer ${token}`,
Accept: 'application/json',
};
for (let i = 0; i < items.length; i++) {
const endpoint = this.getNodeParameter('endpoint', i);
const baseUrl = `https://api.clint.digital/v1/${endpoint}`;
try {
const response = await axios_1.default.get(baseUrl, { headers });
returnData.push({ json: response.data });
}
catch (error) {
returnData.push({
json: {
error: error.message,
details: (_a = error.response) === null || _a === void 0 ? void 0 : _a.data,
},
});
}
}
return [returnData];
}
}
exports.ClintSupport = ClintSupport;