freshdesk-node-setup

This commit is contained in:
Ricardo Espinoza 2019-11-06 19:58:18 -05:00
parent 419c22d584
commit 247954c0fa
5 changed files with 130 additions and 2 deletions

View file

@ -0,0 +1,18 @@
import {
ICredentialType,
NodePropertyTypes,
} from 'n8n-workflow';
export class FreshdeskApi implements ICredentialType {
name = 'freshdeskApi';
displayName = 'Freshdesk API';
properties = [
{
displayName: 'API Key',
name: 'apiKey',
type: 'string' as NodePropertyTypes,
default: '',
},
];
}

View file

@ -0,0 +1,56 @@
import {
IExecuteSingleFunctions,
} from 'n8n-core';
import {
IDataObject,
INodeTypeDescription,
INodeExecutionData,
INodeType,
ILoadOptionsFunctions,
INodePropertyOptions,
} from 'n8n-workflow';
import {
freshdeskApiRequest
} from './GenericFunctions';
import moment = require('moment');
import _ = require('lodash')
export class Freshdesk implements INodeType {
description: INodeTypeDescription = {
displayName: 'Freshdesk',
name: 'freshdesk',
icon: 'file:freshdesk.png',
group: ['output'],
version: 1,
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
description: 'Consume Freshdesk API',
defaults: {
name: 'Freshdesk',
color: '#c02428',
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'freshdeskApi',
required: true,
}
],
properties: [
]
};
methods = {
loadOptions: {
}
};
// async executeSingle(this: IExecuteSingleFunctions): Promise<INodeExecutionData> {
// }
}

View file

@ -0,0 +1,52 @@
import { OptionsWithUri } from 'request';
import {
IExecuteFunctions,
IHookFunctions,
ILoadOptionsFunctions,
IExecuteSingleFunctions
} from 'n8n-core';
import * as _ from 'lodash';
import { IDataObject } from 'n8n-workflow';
export async function freshdeskApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, resource: string, method: string, action: string, body: any = {}, headers?: object): Promise<any> { // tslint:disable-line:no-any
const credentials = this.getCredentials('mandrillApi');
if (credentials === undefined) {
throw new Error('No credentials got returned!');
}
const data = Object.assign({}, body, { key: credentials.apiKey });
const endpoint = 'mandrillapp.com/api/1.0';
const options: OptionsWithUri = {
headers,
method,
uri: `https://${endpoint}${resource}${action}.json`,
body: data,
json: true
};
try {
return await this.helpers.request!(options);
} catch (error) {
console.error(error);
const errorMessage = error.response.body.message || error.response.body.Message;
if (error.name === 'Invalid_Key') {
throw new Error('The provided API key is not a valid Mandrill API key');
} else if (error.name === 'ValidationError') {
throw new Error('The parameters passed to the API call are invalid or not provided when required');
} else if (error.name === 'GeneralError') {
throw new Error('An unexpected error occurred processing the request. Mandrill developers will be notified.');
}
if (errorMessage !== undefined) {
throw errorMessage;
}
throw error.response.body;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

View file

@ -56,7 +56,8 @@
"dist/credentials/TrelloApi.credentials.js",
"dist/credentials/TwilioApi.credentials.js",
"dist/credentials/TypeformApi.credentials.js",
"dist/credentials/MandrillApi.credentials.js"
"dist/credentials/MandrillApi.credentials.js",
"dist/credentials/FreshdeskApi.credentials.js"
],
"nodes": [
"dist/nodes/ActiveCampaign/ActiveCampaign.node.js",
@ -122,7 +123,8 @@
"dist/nodes/WriteBinaryFile.node.js",
"dist/nodes/Webhook.node.js",
"dist/nodes/Xml.node.js",
"dist/nodes/Mandrill/Mandrill.node.js"
"dist/nodes/Mandrill/Mandrill.node.js",
"dist/nodes/Freshdesk/Freshdesk.node.js"
]
},
"devDependencies": {