mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
UI changes
This commit is contained in:
@@ -4,31 +4,38 @@ import {
|
||||
IExecuteFunctions,
|
||||
IHookFunctions,
|
||||
ILoadOptionsFunctions,
|
||||
IExecuteSingleFunctions
|
||||
IExecuteSingleFunctions,
|
||||
BINARY_ENCODING
|
||||
} 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');
|
||||
export async function freshdeskApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, resource: string, method: string, body: any = {}, headers?: object): Promise<any> { // tslint:disable-line:no-any
|
||||
|
||||
const credentials = this.getCredentials('freshdeskApi');
|
||||
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
}
|
||||
|
||||
const data = Object.assign({}, body, { key: credentials.apiKey });
|
||||
const userpass = `${credentials.username}:${credentials.password}`
|
||||
|
||||
const endpoint = 'mandrillapp.com/api/1.0';
|
||||
const headerWithAuthentication = Object.assign({}, headers, { Authorization: `Basic ${Buffer.from(userpass).toString(BINARY_ENCODING)}` });
|
||||
|
||||
const endpoint = 'freshdesk.com/api/v2/';
|
||||
|
||||
const options: OptionsWithUri = {
|
||||
headers,
|
||||
headers: headerWithAuthentication,
|
||||
method,
|
||||
uri: `https://${endpoint}${resource}${action}.json`,
|
||||
body: data,
|
||||
body,
|
||||
uri: `https://${credentials.domain}.${endpoint}${resource}`,
|
||||
json: true
|
||||
};
|
||||
|
||||
if (_.isEmpty(options.body)) {
|
||||
delete options.body
|
||||
}
|
||||
|
||||
try {
|
||||
return await this.helpers.request!(options);
|
||||
@@ -36,13 +43,6 @@ export async function freshdeskApiRequest(this: IHookFunctions | IExecuteFunctio
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user