Small improvements on Freshdesk-Node

This commit is contained in:
Jan Oberhauser 2020-02-21 15:07:03 +01:00
parent 3b346ee829
commit 52ec6dcaf7
3 changed files with 157 additions and 186 deletions

View file

@ -18,7 +18,8 @@ export class FreshdeskApi implements ICredentialType {
displayName: 'Domain', displayName: 'Domain',
name: 'domain', name: 'domain',
type: 'string' as NodePropertyTypes, type: 'string' as NodePropertyTypes,
placeholder: 'https://domain.freshdesk.com', placeholder: 'company',
description: 'If the URL you get displayed on Freshdesk is "https://company.freshdesk.com" enter "company"',
default: '' default: ''
} }
]; ];

View file

@ -12,7 +12,7 @@ import {
import { import {
freshdeskApiRequest, freshdeskApiRequest,
freshdeskApiRequestAllItems, freshdeskApiRequestAllItems,
validateJSON, // validateJSON,
capitalize capitalize
} from './GenericFunctions'; } from './GenericFunctions';
@ -121,9 +121,9 @@ export class Freshdesk implements INodeType {
description: 'Create a new ticket', description: 'Create a new ticket',
}, },
{ {
name: 'Update', name: 'Delete',
value: 'update', value: 'delete',
description: 'Update a ticket', description: 'Delete a ticket',
}, },
{ {
name: 'Get', name: 'Get',
@ -136,9 +136,9 @@ export class Freshdesk implements INodeType {
description: 'Get all tickets', description: 'Get all tickets',
}, },
{ {
name: 'Delete', name: 'Update',
value: 'delete', value: 'update',
description: 'Delete a ticket', description: 'Update a ticket',
}, },
], ],
default: 'create', default: 'create',
@ -155,16 +155,11 @@ export class Freshdesk implements INodeType {
'ticket', 'ticket',
], ],
operation: [ operation: [
'create' 'create',
] ]
}, },
}, },
options: [ options: [
{
name: 'Requester Id',
value: 'requesterId',
description: `User ID of the requester. For existing contacts, the requester_id can be passed instead of the requester's email.`,
},
{ {
name: 'Email', name: 'Email',
value: 'email', value: 'email',
@ -180,6 +175,11 @@ export class Freshdesk implements INodeType {
value: 'phone', value: 'phone',
description: `Phone number of the requester. If no contact exists with this phone number in Freshdesk, it will be added as a new contact. If the phone number is set and the email address is not, then the name attribute is mandatory.`, description: `Phone number of the requester. If no contact exists with this phone number in Freshdesk, it will be added as a new contact. If the phone number is set and the email address is not, then the name attribute is mandatory.`,
}, },
{
name: 'Requester Id',
value: 'requesterId',
description: `User ID of the requester. For existing contacts, the requester_id can be passed instead of the requester's email.`,
},
{ {
name: 'Twitter Id', name: 'Twitter Id',
value: 'twitterId', value: 'twitterId',
@ -205,7 +205,7 @@ export class Freshdesk implements INodeType {
'ticket', 'ticket',
], ],
operation: [ operation: [
'create' 'create',
] ]
}, },
}, },
@ -223,11 +223,15 @@ export class Freshdesk implements INodeType {
'ticket', 'ticket',
], ],
operation: [ operation: [
'create' 'create',
] ]
}, },
}, },
options: [ options: [
{
name: 'Closed',
value: 'closed',
},
{ {
name: 'Open', name: 'Open',
value: 'open', value: 'open',
@ -240,10 +244,6 @@ export class Freshdesk implements INodeType {
name: 'Resolved', name: 'Resolved',
value: 'resolved', value: 'resolved',
}, },
{
name: 'Closed',
value: 'closed',
}
], ],
default: 'pending', default: 'pending',
description: 'Status', description: 'Status',
@ -300,34 +300,35 @@ export class Freshdesk implements INodeType {
}, },
}, },
options: [ options: [
{
name: 'Email',
value: 'email',
},
{
name: 'Portal',
value: 'portal',
},
{
name: 'Phone',
value: 'phone',
},
{ {
name: 'Chat', name: 'Chat',
value: 'chat', value: 'chat',
}, },
{ {
name: 'Mobihelp', name: 'Email',
value: 'mobileHelp', value: 'email',
}, },
{ {
name: 'Feedback Widget', name: 'Feedback Widget',
value: 'feedbackWidget', value: 'feedbackWidget',
}, },
{
name: 'Phone',
value: 'phone',
},
{
name: 'Portal',
value: 'portal',
},
{
name: 'Mobihelp',
value: 'mobileHelp',
},
{ {
name: 'Outbound Email', name: 'Outbound Email',
value: 'OutboundEmail', value: 'OutboundEmail',
} },
], ],
default: 'portal', default: 'portal',
description: 'The channel through which the ticket was created.', description: 'The channel through which the ticket was created.',
@ -358,10 +359,10 @@ export class Freshdesk implements INodeType {
displayOptions: { displayOptions: {
show: { show: {
resource: [ resource: [
'ticket' 'ticket',
], ],
operation: [ operation: [
'create' 'create',
], ],
}, },
}, },
@ -370,29 +371,26 @@ export class Freshdesk implements INodeType {
displayName: 'Agent', displayName: 'Agent',
name: 'agent', name: 'agent',
type: 'options', type: 'options',
required: false,
default: '', default: '',
typeOptions: { typeOptions: {
loadOptionsMethod: 'getAgents' loadOptionsMethod: 'getAgents',
}, },
description: 'ID of the agent to whom the ticket has been assigned', description: 'ID of the agent to whom the ticket has been assigned',
}, },
{ {
displayName: 'CC Emails', displayName: 'CC Emails',
name: 'ccEmails', name: 'ccEmails',
required: false,
type: 'string', type: 'string',
default: '', default: '',
description: `separated by , email addresses added in the 'cc' field of the incoming ticket email`, description: `Separated by , email addresses added in the 'cc' field of the incoming ticket email`,
}, },
{ {
displayName: 'Company', displayName: 'Company',
name: 'company', name: 'company',
required: false,
type: 'options', type: 'options',
default: '', default: '',
typeOptions: { typeOptions: {
loadOptionsMethod: 'getCompanies' loadOptionsMethod: 'getCompanies',
}, },
description: `Company ID of the requester. This attribute can only be set if the Multiple Companies feature is enabled (Estate plan and above)`, description: `Company ID of the requester. This attribute can only be set if the Multiple Companies feature is enabled (Estate plan and above)`,
}, },
@ -400,7 +398,6 @@ export class Freshdesk implements INodeType {
displayName: 'Description', displayName: 'Description',
name: 'description', name: 'description',
type: 'string', type: 'string',
required: false,
default: '', default: '',
typeOptions: { typeOptions: {
rows: 5, rows: 5,
@ -411,7 +408,6 @@ export class Freshdesk implements INodeType {
{ {
displayName: 'Due By', displayName: 'Due By',
name: 'dueBy', name: 'dueBy',
required: false,
type: 'dateTime', type: 'dateTime',
default: '', default: '',
description: `Timestamp that denotes when the ticket is due to be resolved`, description: `Timestamp that denotes when the ticket is due to be resolved`,
@ -420,7 +416,6 @@ export class Freshdesk implements INodeType {
displayName: 'Email config Id', displayName: 'Email config Id',
name: 'emailConfigId', name: 'emailConfigId',
type: 'number', type: 'number',
required: false,
default: '', default: '',
description: `ID of email config which is used for this ticket. (i.e., support@yourcompany.com/sales@yourcompany.com) description: `ID of email config which is used for this ticket. (i.e., support@yourcompany.com/sales@yourcompany.com)
If product_id is given and email_config_id is not given, product's primary email_config_id will be set`, If product_id is given and email_config_id is not given, product's primary email_config_id will be set`,
@ -429,14 +424,12 @@ export class Freshdesk implements INodeType {
displayName: 'FR Due By', displayName: 'FR Due By',
name: 'frDueBy', name: 'frDueBy',
type: 'dateTime', type: 'dateTime',
required: false,
default: '', default: '',
description: `Timestamp that denotes when the first response is due`, description: `Timestamp that denotes when the first response is due`,
}, },
{ {
displayName: 'Group', displayName: 'Group',
name: 'group', name: 'group',
required: false,
type: 'options', type: 'options',
default: '', default: '',
typeOptions: { typeOptions: {
@ -455,7 +448,6 @@ export class Freshdesk implements INodeType {
{ {
displayName: 'Product', displayName: 'Product',
name: 'product', name: 'product',
required: false,
type: 'options', type: 'options',
default: '', default: '',
typeOptions: { typeOptions: {
@ -475,7 +467,6 @@ export class Freshdesk implements INodeType {
{ {
displayName: 'Tags', displayName: 'Tags',
name: 'tags', name: 'tags',
required: false,
type: 'string', type: 'string',
default: '', default: '',
description: `separated by , tags that have been associated with the ticket`, description: `separated by , tags that have been associated with the ticket`,
@ -488,24 +479,24 @@ export class Freshdesk implements INodeType {
description: 'Helps categorize the ticket according to the different kinds of issues your support team deals with.', description: 'Helps categorize the ticket according to the different kinds of issues your support team deals with.',
options: [ options: [
{ {
name: 'Question', name: 'Feature Request',
value: 'Question' value: 'Feature Request',
}, },
{ {
name: 'Incident', name: 'Incident',
value: 'Incident' value: 'Incident',
}, },
{ {
name: 'Problem', name: 'Problem',
value: 'Problem' value: 'Problem',
}, },
{ {
name: 'Feature Request', name: 'Question',
value: 'Feature Request' value: 'Question',
}, },
{ {
name: 'Refund', name: 'Refund',
value: 'Refund' value: 'Refund',
}, },
] ]
}, },
@ -568,10 +559,10 @@ export class Freshdesk implements INodeType {
// displayOptions: { // displayOptions: {
// show: { // show: {
// resource: [ // resource: [
// 'ticket' // 'ticket',
// ], // ],
// operation: [ // operation: [
// 'create' // 'create',
// ], // ],
// jsonParameters: [ // jsonParameters: [
// true, // true,
@ -581,7 +572,7 @@ export class Freshdesk implements INodeType {
// default: '', // default: '',
// required: false, // required: false,
// placeholder: `{ // placeholder: `{
// "gadget":"Cold Welder" // 'gadget': 'Cold Welder',
// }`, // }`,
// description: 'Key value pairs containing the names and values of custom fields.', // description: 'Key value pairs containing the names and values of custom fields.',
// }, // },
@ -596,7 +587,7 @@ export class Freshdesk implements INodeType {
'ticket', 'ticket',
], ],
operation: [ operation: [
'update' 'update',
] ]
}, },
}, },
@ -612,10 +603,10 @@ export class Freshdesk implements INodeType {
displayOptions: { displayOptions: {
show: { show: {
resource: [ resource: [
'ticket' 'ticket',
], ],
operation: [ operation: [
'update' 'update',
], ],
}, },
}, },
@ -624,36 +615,32 @@ export class Freshdesk implements INodeType {
displayName: 'Agent', displayName: 'Agent',
name: 'agent', name: 'agent',
type: 'options', type: 'options',
required: false,
default: '', default: '',
typeOptions: { typeOptions: {
loadOptionsMethod: 'getAgents' loadOptionsMethod: 'getAgents',
}, },
description: 'ID of the agent to whom the ticket has been assigned', description: 'ID of the agent to whom the ticket has been assigned',
}, },
{ {
displayName: 'CC Emails', displayName: 'CC Emails',
name: 'ccEmails', name: 'ccEmails',
required: false,
type: 'string', type: 'string',
default: '', default: '',
description: `separated by , email addresses added in the 'cc' field of the incoming ticket email`, description: `Separated by , email addresses added in the 'cc' field of the incoming ticket email`,
}, },
{ {
displayName: 'Company', displayName: 'Company',
name: 'company', name: 'company',
required: false,
type: 'options', type: 'options',
default: '', default: '',
typeOptions: { typeOptions: {
loadOptionsMethod: 'getCompanies' loadOptionsMethod: 'getCompanies',
}, },
description: `Company ID of the requester. This attribute can only be set if the Multiple Companies feature is enabled (Estate plan and above)`, description: `Company ID of the requester. This attribute can only be set if the Multiple Companies feature is enabled (Estate plan and above)`,
}, },
{ {
displayName: 'Due By', displayName: 'Due By',
name: 'dueBy', name: 'dueBy',
required: false,
type: 'dateTime', type: 'dateTime',
default: '', default: '',
description: `Timestamp that denotes when the ticket is due to be resolved`, description: `Timestamp that denotes when the ticket is due to be resolved`,
@ -662,7 +649,6 @@ export class Freshdesk implements INodeType {
displayName: 'Email config Id', displayName: 'Email config Id',
name: 'emailConfigId', name: 'emailConfigId',
type: 'number', type: 'number',
required: false,
default: '', default: '',
description: `ID of email config which is used for this ticket. (i.e., support@yourcompany.com/sales@yourcompany.com) description: `ID of email config which is used for this ticket. (i.e., support@yourcompany.com/sales@yourcompany.com)
If product_id is given and email_config_id is not given, product's primary email_config_id will be set`, If product_id is given and email_config_id is not given, product's primary email_config_id will be set`,
@ -671,18 +657,16 @@ export class Freshdesk implements INodeType {
displayName: 'FR Due By', displayName: 'FR Due By',
name: 'frDueBy', name: 'frDueBy',
type: 'dateTime', type: 'dateTime',
required: false,
default: '', default: '',
description: `Timestamp that denotes when the first response is due`, description: `Timestamp that denotes when the first response is due`,
}, },
{ {
displayName: 'Group', displayName: 'Group',
name: 'group', name: 'group',
required: false,
type: 'options', type: 'options',
default: '', default: '',
typeOptions: { typeOptions: {
loadOptionsMethod: 'getGroups' loadOptionsMethod: 'getGroups',
}, },
description: `ID of the group to which the ticket has been assigned. The default value is the ID of the group that is associated with the given email_config_id`, description: `ID of the group to which the ticket has been assigned. The default value is the ID of the group that is associated with the given email_config_id`,
}, },
@ -697,11 +681,10 @@ export class Freshdesk implements INodeType {
{ {
displayName: 'Product', displayName: 'Product',
name: 'product', name: 'product',
required: false,
type: 'options', type: 'options',
default: '', default: '',
typeOptions: { typeOptions: {
loadOptionsMethod: 'getProducts' loadOptionsMethod: 'getProducts',
}, },
description: `ID of the product to which the ticket is associated. description: `ID of the product to which the ticket is associated.
It will be ignored if the email_config_id attribute is set in the request.`, It will be ignored if the email_config_id attribute is set in the request.`,
@ -737,11 +720,6 @@ export class Freshdesk implements INodeType {
name: 'requester', name: 'requester',
type: 'options', type: 'options',
options: [ options: [
{
name: 'Requester Id',
value: 'requesterId',
description: `User ID of the requester. For existing contacts, the requester_id can be passed instead of the requester's email.`,
},
{ {
name: 'Email', name: 'Email',
value: 'email', value: 'email',
@ -757,6 +735,11 @@ export class Freshdesk implements INodeType {
value: 'phone', value: 'phone',
description: `Phone number of the requester. If no contact exists with this phone number in Freshdesk, it will be added as a new contact. If the phone number is set and the email address is not, then the name attribute is mandatory.`, description: `Phone number of the requester. If no contact exists with this phone number in Freshdesk, it will be added as a new contact. If the phone number is set and the email address is not, then the name attribute is mandatory.`,
}, },
{
name: 'Requester Id',
value: 'requesterId',
description: `User ID of the requester. For existing contacts, the requester_id can be passed instead of the requester's email.`,
},
{ {
name: 'Twitter Id', name: 'Twitter Id',
value: 'twitterId', value: 'twitterId',
@ -810,34 +793,35 @@ export class Freshdesk implements INodeType {
type: 'options', type: 'options',
required: true, required: true,
options: [ options: [
{
name: 'Email',
value: 'email',
},
{
name: 'Portal',
value: 'portal',
},
{
name: 'Phone',
value: 'phone',
},
{ {
name: 'Chat', name: 'Chat',
value: 'chat', value: 'chat',
}, },
{ {
name: 'Mobihelp', name: 'Email',
value: 'mobileHelp', value: 'email',
}, },
{ {
name: 'Feedback Widget', name: 'Feedback Widget',
value: 'feedbackWidget', value: 'feedbackWidget',
}, },
{
name: 'Mobihelp',
value: 'mobileHelp',
},
{ {
name: 'Outbound Email', name: 'Outbound Email',
value: 'OutboundEmail', value: 'OutboundEmail',
} },
{
name: 'Phone',
value: 'phone',
},
{
name: 'Portal',
value: 'portal',
},
], ],
default: 'portal', default: 'portal',
description: 'The channel through which the ticket was created.', description: 'The channel through which the ticket was created.',
@ -845,7 +829,6 @@ export class Freshdesk implements INodeType {
{ {
displayName: 'Tags', displayName: 'Tags',
name: 'tags', name: 'tags',
required: false,
type: 'string', type: 'string',
default: '', default: '',
description: `separated by , tags that have been associated with the ticket`, description: `separated by , tags that have been associated with the ticket`,
@ -858,8 +841,8 @@ export class Freshdesk implements INodeType {
description: 'Helps categorize the ticket according to the different kinds of issues your support team deals with.', description: 'Helps categorize the ticket according to the different kinds of issues your support team deals with.',
options: [ options: [
{ {
name: 'Question', name: 'Feature Request',
value: 'Question' value: 'Feature Request'
}, },
{ {
name: 'Incident', name: 'Incident',
@ -870,8 +853,8 @@ export class Freshdesk implements INodeType {
value: 'Problem' value: 'Problem'
}, },
{ {
name: 'Feature Request', name: 'Question',
value: 'Feature Request' value: 'Question'
}, },
{ {
name: 'Refund', name: 'Refund',
@ -957,6 +940,53 @@ export class Freshdesk implements INodeType {
}, },
}, },
options: [ options: [
{
displayName: 'Company ID',
name: 'companyId',
type: 'string',
default: '',
},
{
displayName: 'Include',
name: 'include',
type: 'multiOptions',
options: [
{
name: 'Company',
value: 'company',
},
{
name: 'Description',
value: 'description',
},
{
name: 'Requester',
value: 'requester',
},
{
name: 'Stats',
value: 'stats',
},
],
default: [],
},
{
displayName: 'Order',
name: 'order',
type: 'options',
options: [
{
name: 'ASC',
value: 'asc',
},
{
name: 'DESC',
value: 'desc',
},
],
default: 'desc',
description: 'Order sort attribute ascending or descending.',
},
{ {
displayName: 'Order By', displayName: 'Order By',
name: 'orderBy', name: 'orderBy',
@ -978,29 +1008,6 @@ export class Freshdesk implements INodeType {
default: '', default: '',
description: 'Sort collection by object attribute.', description: 'Sort collection by object attribute.',
}, },
{
displayName: 'Order',
name: 'order',
type: 'options',
options: [
{
name: 'ASC',
value: 'asc',
},
{
name: 'DESC',
value: 'desc',
},
],
default: 'desc',
description: 'Order sort attribute ascending or descending.',
},
{
displayName: 'Requester ID',
name: 'requesterId',
type: 'string',
default: '',
},
{ {
displayName: 'Requester Email', displayName: 'Requester Email',
name: 'requesterEmail', name: 'requesterEmail',
@ -1008,35 +1015,11 @@ export class Freshdesk implements INodeType {
default: '', default: '',
}, },
{ {
displayName: 'Company ID', displayName: 'Requester ID',
name: 'companyId', name: 'requesterId',
type: 'string', type: 'string',
default: '', default: '',
}, },
{
displayName: 'Include',
name: 'include',
type: 'multiOptions',
options: [
{
name: 'Stats',
value: 'stats',
},
{
name: 'Requester',
value: 'requester',
},
{
name: 'Description',
value: 'description',
},
{
name: 'Company',
value: 'company',
},
],
default: [],
},
{ {
displayName: 'Updated Since', displayName: 'Updated Since',
name: 'updatedSince', name: 'updatedSince',
@ -1072,12 +1055,7 @@ export class Freshdesk implements INodeType {
// select them easily // select them easily
async getAgents(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> { async getAgents(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = []; const returnData: INodePropertyOptions[] = [];
let agents; const agents = await freshdeskApiRequest.call(this, 'GET', '/agents');
try {
agents = await freshdeskApiRequest.call(this, 'GET', '/agents');
} catch (err) {
throw new Error(`Freshdesk Error: ${err}`);
}
for (const agent of agents) { for (const agent of agents) {
const agentName = agent.contact.name; const agentName = agent.contact.name;
const agentId = agent.id; const agentId = agent.id;
@ -1094,12 +1072,7 @@ export class Freshdesk implements INodeType {
// select them easily // select them easily
async getGroups(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> { async getGroups(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = []; const returnData: INodePropertyOptions[] = [];
let groups; const groups = await freshdeskApiRequest.call(this, 'GET', '/groups');
try {
groups = await freshdeskApiRequest.call(this, 'GET', '/groups');
} catch (err) {
throw new Error(`Freshdesk Error: ${err}`);
}
for (const group of groups) { for (const group of groups) {
const groupName = group.name; const groupName = group.name;
const groupId = group.id; const groupId = group.id;
@ -1116,12 +1089,7 @@ export class Freshdesk implements INodeType {
// select them easily // select them easily
async getProducts(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> { async getProducts(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = []; const returnData: INodePropertyOptions[] = [];
let products; const products = await freshdeskApiRequest.call(this, 'GET', '/products');
try {
products = await freshdeskApiRequest.call(this, 'GET', '/products');
} catch (err) {
throw new Error(`Freshdesk Error: ${err}`);
}
for (const product of products) { for (const product of products) {
const productName = product.name; const productName = product.name;
const productId = product.id; const productId = product.id;
@ -1138,12 +1106,7 @@ export class Freshdesk implements INodeType {
// select them easily // select them easily
async getCompanies(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> { async getCompanies(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = []; const returnData: INodePropertyOptions[] = [];
let companies; const companies = await freshdeskApiRequest.call(this, 'GET', '/companies');
try {
companies = await freshdeskApiRequest.call(this, 'GET', '/companies');
} catch (err) {
throw new Error(`Freshdesk Error: ${err}`);
}
for (const company of companies) { for (const company of companies) {
const companyName = company.name; const companyName = company.name;
const companyId = company.id; const companyId = company.id;
@ -1161,13 +1124,11 @@ export class Freshdesk implements INodeType {
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> { async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData(); const items = this.getInputData();
const returnData: IDataObject[] = []; const returnData: IDataObject[] = [];
const length = items.length as unknown as number;
let responseData; let responseData;
const qs: IDataObject = {}; const qs: IDataObject = {};
const resource = this.getNodeParameter('resource', 0) as string; const resource = this.getNodeParameter('resource', 0) as string;
const operation = this.getNodeParameter('operation', 0) as string; const operation = this.getNodeParameter('operation', 0) as string;
let response; for (let i = 0; i < items.length; i++) {
for (let i = 0; i < length; i++) {
if (resource === 'ticket') { if (resource === 'ticket') {
//https://developers.freshdesk.com/api/#create_ticket //https://developers.freshdesk.com/api/#create_ticket
if (operation === 'create') { if (operation === 'create') {
@ -1292,15 +1253,15 @@ export class Freshdesk implements INodeType {
} }
if (updateFields.status) { if (updateFields.status) {
//@ts-ignore //@ts-ignore
body.status = Status[capitalize(updateFields.status)] body.status = Status[capitalize(updateFields.status)];
} }
if (updateFields.priority) { if (updateFields.priority) {
//@ts-ignore //@ts-ignore
body.priority = Priority[capitalize(updateFields.priority)] body.priority = Priority[capitalize(updateFields.priority)];
} }
if (updateFields.source) { if (updateFields.source) {
//@ts-ignore //@ts-ignore
body.source = Source[capitalize(updateFields.source)] body.source = Source[capitalize(updateFields.source)];
} }
if (updateFields.name) { if (updateFields.name) {
body.name = updateFields.name as string; body.name = updateFields.name as string;
@ -1385,6 +1346,12 @@ export class Freshdesk implements INodeType {
if (Array.isArray(responseData)) { if (Array.isArray(responseData)) {
returnData.push.apply(returnData, responseData as IDataObject[]); returnData.push.apply(returnData, responseData as IDataObject[]);
} else { } else {
if (responseData === undefined) {
responseData = { json: {
success: true,
} };
}
returnData.push(responseData as IDataObject); returnData.push(responseData as IDataObject);
} }
} }

View file

@ -41,12 +41,15 @@ export async function freshdeskApiRequest(this: IExecuteFunctions | ILoadOptions
try { try {
return await this.helpers.request!(options); return await this.helpers.request!(options);
} catch (error) { } catch (error) {
console.log(error.response.body) if (error.response) {
const errorMessage = error.response.body.message || error.response.body.Message || error.response.body.description; let errorMessage = error.response.body.message || error.response.body.description || error.message;
if (errorMessage !== undefined) { if (error.response.body && error.response.body.errors) {
throw new Error(errorMessage); errorMessage = error.response.body.errors.map((err: IDataObject) => `"${err.field}" => ${err.message}`).join(', ');
}; }
return new Error(error) throw new Error(`Freshdesk error response [${error.statusCode}]: ${errorMessage}`);
}
throw error;
} }
} }