2023-01-27 03:22:44 -08:00
import type {
2023-03-09 09:13:15 -08:00
IExecuteFunctions ,
2019-11-08 08:26:09 -08:00
IDataObject ,
ILoadOptionsFunctions ,
2020-10-01 05:01:39 -07:00
INodeExecutionData ,
2019-11-08 08:26:09 -08:00
INodePropertyOptions ,
2020-10-01 05:01:39 -07:00
INodeType ,
INodeTypeDescription ,
2019-11-08 08:26:09 -08:00
} from 'n8n-workflow' ;
2024-08-29 06:55:53 -07:00
import { NodeConnectionType , NodeOperationError } from 'n8n-workflow' ;
2020-09-10 12:56:15 -07:00
2019-11-08 08:26:09 -08:00
import {
2020-10-01 05:01:39 -07:00
capitalize ,
2019-11-08 08:26:09 -08:00
freshdeskApiRequest ,
2020-02-18 11:03:48 -08:00
freshdeskApiRequestAllItems ,
2020-02-21 06:07:03 -08:00
// validateJSON,
2019-11-08 08:26:09 -08:00
} from './GenericFunctions' ;
2023-01-27 03:22:44 -08:00
import type { ICreateContactBody } from './ContactInterface' ;
2020-09-10 12:56:15 -07:00
2022-08-01 13:47:55 -07:00
import { contactFields , contactOperations } from './ContactDescription' ;
2020-09-10 12:56:15 -07:00
2023-04-21 04:23:15 -07:00
const enum Status {
2019-11-10 03:33:23 -08:00
Open = 2 ,
Pending = 3 ,
Resolved = 4 ,
Closed = 5 ,
2019-11-08 08:26:09 -08:00
}
2023-04-21 04:23:15 -07:00
const enum Priority {
2019-11-08 08:26:09 -08:00
Low = 1 ,
Medium = 2 ,
High = 3 ,
2020-10-22 06:46:03 -07:00
Urgent = 4 ,
2019-11-08 08:26:09 -08:00
}
2023-04-21 04:23:15 -07:00
const enum Source {
2019-11-08 08:26:09 -08:00
Email = 1 ,
Portal = 2 ,
Phone = 3 ,
2019-11-10 05:08:56 -08:00
Chat = 7 ,
Mobihelp = 8 ,
FeedbackWidget = 9 ,
2019-11-13 05:29:47 -08:00
OutboundEmail = 10 ,
2019-11-08 08:26:09 -08:00
}
2019-11-10 14:14:36 -08:00
interface ICreateTicketBody {
2019-11-08 08:26:09 -08:00
name? : string ;
requester_id? : number ;
email? : string ;
facebook_id? : string ;
phone? : string ;
twitter_id? : string ;
unique_external_id? : string ;
subject? : string | null ;
type ? : string ;
2020-02-18 11:03:48 -08:00
status? : Status ;
priority? : Priority ;
2019-11-08 08:26:09 -08:00
description? : string ;
responder_id? : number ;
cc_emails ? : [ string ] ;
custom_fields? : IDataObject ;
due_by? : string ;
email_config_id? : number ;
fr_due_by? : string ;
group_id? : number ;
product_id? : number ;
2020-02-18 11:03:48 -08:00
source? : Source ;
2019-11-08 08:26:09 -08:00
tags ? : [ string ] ;
company_id? : number ;
}
export class Freshdesk implements INodeType {
description : INodeTypeDescription = {
displayName : 'Freshdesk' ,
name : 'freshdesk' ,
2024-06-24 03:13:18 -07:00
2024-06-06 04:34:30 -07:00
icon : 'file:freshdesk.svg' ,
2019-11-08 08:26:09 -08:00
group : [ 'output' ] ,
version : 1 ,
subtitle : '={{$parameter["operation"] + ": " + $parameter["resource"]}}' ,
description : 'Consume Freshdesk API' ,
defaults : {
name : 'Freshdesk' ,
} ,
2024-08-29 06:55:53 -07:00
inputs : [ NodeConnectionType . Main ] ,
outputs : [ NodeConnectionType . Main ] ,
2019-11-08 08:26:09 -08:00
credentials : [
{
name : 'freshdeskApi' ,
required : true ,
2020-02-18 11:03:48 -08:00
} ,
2019-11-10 14:14:36 -08:00
] ,
2019-11-08 08:26:09 -08:00
properties : [
{
displayName : 'Resource' ,
name : 'resource' ,
type : 'options' ,
2022-05-20 14:47:24 -07:00
noDataExpression : true ,
2019-11-08 08:26:09 -08:00
required : true ,
options : [
2020-09-10 12:56:15 -07:00
{
name : 'Contact' ,
value : 'contact' ,
} ,
2019-11-08 08:26:09 -08:00
{
name : 'Ticket' ,
value : 'ticket' ,
} ,
] ,
default : 'ticket' ,
} ,
{
displayName : 'Operation' ,
name : 'operation' ,
type : 'options' ,
2022-05-20 14:47:24 -07:00
noDataExpression : true ,
2019-11-08 08:26:09 -08:00
required : true ,
displayOptions : {
show : {
2022-08-01 13:47:55 -07:00
resource : [ 'ticket' ] ,
2019-11-08 08:26:09 -08:00
} ,
} ,
options : [
{
name : 'Create' ,
value : 'create' ,
description : 'Create a new ticket' ,
2022-07-10 13:50:51 -07:00
action : 'Create a ticket' ,
2020-02-18 11:03:48 -08:00
} ,
{
2020-02-21 06:07:03 -08:00
name : 'Delete' ,
value : 'delete' ,
description : 'Delete a ticket' ,
2022-07-10 13:50:51 -07:00
action : 'Delete a ticket' ,
2020-02-18 11:03:48 -08:00
} ,
{
name : 'Get' ,
value : 'get' ,
description : 'Get a ticket' ,
2022-07-10 13:50:51 -07:00
action : 'Get a ticket' ,
2020-02-18 11:03:48 -08:00
} ,
{
2022-09-07 07:51:14 -07:00
name : 'Get Many' ,
2020-02-18 11:03:48 -08:00
value : 'getAll' ,
2022-09-13 03:36:36 -07:00
description : 'Get many tickets' ,
2022-09-08 08:10:13 -07:00
action : 'Get many tickets' ,
2020-02-18 11:03:48 -08:00
} ,
{
2020-02-21 06:07:03 -08:00
name : 'Update' ,
value : 'update' ,
description : 'Update a ticket' ,
2022-07-10 13:50:51 -07:00
action : 'Update a ticket' ,
2020-02-18 11:03:48 -08:00
} ,
2019-11-08 08:26:09 -08:00
] ,
default : 'create' ,
} ,
{
displayName : 'Requester Identification' ,
name : 'requester' ,
type : 'options' ,
required : true ,
displayOptions : {
show : {
2022-08-01 13:47:55 -07:00
resource : [ 'ticket' ] ,
operation : [ 'create' ] ,
2019-11-08 08:26:09 -08:00
} ,
} ,
options : [
{
name : 'Email' ,
value : 'email' ,
2022-08-01 13:47:55 -07:00
description :
'Email address of the requester. If no contact exists with this email address in Freshdesk, it will be added as a new contact.' ,
2019-11-08 08:26:09 -08:00
} ,
{
2022-05-20 14:47:24 -07:00
name : 'Facebook ID' ,
2019-11-08 08:26:09 -08:00
value : 'facebookId' ,
2022-08-01 13:47:55 -07:00
description :
'Facebook ID of the requester. If no contact exists with this facebook_id, then a new contact will be created.' ,
2019-11-08 08:26:09 -08:00
} ,
{
name : 'Phone' ,
value : 'phone' ,
2022-08-01 13:47:55 -07:00
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.' ,
2019-11-08 08:26:09 -08:00
} ,
2020-02-21 06:07:03 -08:00
{
2022-05-20 14:47:24 -07:00
name : 'Requester ID' ,
2020-02-21 06:07:03 -08:00
value : 'requesterId' ,
2022-08-01 13:47:55 -07:00
description :
"User ID of the requester. For existing contacts, the requester_id can be passed instead of the requester's email." ,
2020-02-21 06:07:03 -08:00
} ,
2019-11-08 08:26:09 -08:00
{
2022-05-20 14:47:24 -07:00
name : 'Twitter ID' ,
2019-11-08 08:26:09 -08:00
value : 'twitterId' ,
2022-08-01 13:47:55 -07:00
description :
'Twitter handle of the requester. If no contact exists with this handle in Freshdesk, it will be added as a new contact.' ,
2019-11-08 08:26:09 -08:00
} ,
{
2022-05-20 14:47:24 -07:00
name : 'Unique External ID' ,
2019-11-08 08:26:09 -08:00
value : 'uniqueExternalId' ,
2022-08-01 13:47:55 -07:00
description :
'External ID of the requester. If no contact exists with this external ID in Freshdesk, they will be added as a new contact.' ,
2019-11-08 08:26:09 -08:00
} ,
] ,
default : 'requesterId' ,
} ,
{
displayName : 'Value' ,
name : 'requesterIdentificationValue' ,
type : 'string' ,
required : true ,
displayOptions : {
show : {
2022-08-01 13:47:55 -07:00
resource : [ 'ticket' ] ,
operation : [ 'create' ] ,
2019-11-08 08:26:09 -08:00
} ,
} ,
default : '' ,
2022-05-06 14:01:25 -07:00
description : 'Value of the identification selected' ,
2019-11-08 08:26:09 -08:00
} ,
{
displayName : 'Status' ,
name : 'status' ,
type : 'options' ,
required : true ,
displayOptions : {
show : {
2022-08-01 13:47:55 -07:00
resource : [ 'ticket' ] ,
operation : [ 'create' ] ,
2019-11-08 08:26:09 -08:00
} ,
} ,
options : [
2020-02-21 06:07:03 -08:00
{
name : 'Closed' ,
value : 'closed' ,
} ,
2019-11-08 08:26:09 -08:00
{
name : 'Open' ,
value : 'open' ,
} ,
{
name : 'Pending' ,
value : 'pending' ,
} ,
{
name : 'Resolved' ,
value : 'resolved' ,
} ,
] ,
default : 'pending' ,
} ,
{
displayName : 'Priority' ,
name : 'priority' ,
type : 'options' ,
required : true ,
displayOptions : {
show : {
2022-08-01 13:47:55 -07:00
resource : [ 'ticket' ] ,
operation : [ 'create' ] ,
2019-11-08 08:26:09 -08:00
} ,
} ,
options : [
{
name : 'Low' ,
value : 'low' ,
} ,
{
name : 'Medium' ,
value : 'medium' ,
} ,
{
name : 'High' ,
value : 'high' ,
} ,
{
name : 'Urgent' ,
value : 'urgent' ,
2020-10-22 06:46:03 -07:00
} ,
2019-11-08 08:26:09 -08:00
] ,
default : 'low' ,
} ,
{
displayName : 'Source' ,
name : 'source' ,
type : 'options' ,
required : true ,
displayOptions : {
show : {
2022-08-01 13:47:55 -07:00
resource : [ 'ticket' ] ,
operation : [ 'create' ] ,
2019-11-08 08:26:09 -08:00
} ,
} ,
options : [
2020-02-21 06:07:03 -08:00
{
name : 'Chat' ,
value : 'chat' ,
} ,
2019-11-08 08:26:09 -08:00
{
name : 'Email' ,
value : 'email' ,
} ,
{
2020-02-21 06:07:03 -08:00
name : 'Feedback Widget' ,
value : 'feedbackWidget' ,
2019-11-08 08:26:09 -08:00
} ,
{
name : 'Mobihelp' ,
value : 'mobileHelp' ,
} ,
{
name : 'Outbound Email' ,
value : 'OutboundEmail' ,
2020-02-21 06:07:03 -08:00
} ,
2022-06-03 10:23:49 -07:00
{
name : 'Phone' ,
value : 'phone' ,
} ,
{
name : 'Portal' ,
value : 'portal' ,
} ,
2019-11-08 08:26:09 -08:00
] ,
default : 'portal' ,
2022-05-06 14:01:25 -07:00
description : 'The channel through which the ticket was created' ,
2019-11-08 08:26:09 -08:00
} ,
// {
// displayName: 'JSON Parameters',
// name: 'jsonParameters',
// type: 'boolean',
// default: false,
// description: '',
// displayOptions: {
// show: {
// resource: [
// 'ticket'
// ],
// operation: [
// 'create',
// ]
// },
// },
// },
{
displayName : 'Options' ,
name : 'options' ,
type : 'collection' ,
2024-07-29 05:27:23 -07:00
placeholder : 'Add option' ,
2019-11-08 08:26:09 -08:00
default : { } ,
displayOptions : {
show : {
2022-08-01 13:47:55 -07:00
resource : [ 'ticket' ] ,
operation : [ 'create' ] ,
2019-11-08 08:26:09 -08:00
} ,
} ,
options : [
{
2022-06-03 10:23:49 -07:00
displayName : 'Agent Name or ID' ,
2019-11-08 08:26:09 -08:00
name : 'agent' ,
type : 'options' ,
default : '' ,
typeOptions : {
2020-02-21 06:07:03 -08:00
loadOptionsMethod : 'getAgents' ,
2019-11-08 08:26:09 -08:00
} ,
2022-08-01 13:47:55 -07:00
description :
'ID of the agent to whom the ticket has been assigned. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.' ,
2019-11-08 08:26:09 -08:00
} ,
{
displayName : 'CC Emails' ,
name : 'ccEmails' ,
type : 'string' ,
default : '' ,
2022-08-01 13:47:55 -07:00
description :
"Separated by a comma (,) email addresses added in the 'cc' field of the incoming ticket email" ,
2019-11-08 08:26:09 -08:00
} ,
{
2022-06-03 10:23:49 -07:00
displayName : 'Company Name or ID' ,
2020-02-18 11:03:48 -08:00
name : 'company' ,
type : 'options' ,
default : '' ,
typeOptions : {
2020-02-21 06:07:03 -08:00
loadOptionsMethod : 'getCompanies' ,
2020-02-18 11:03:48 -08:00
} ,
2022-08-01 13:47:55 -07:00
description :
'Company ID of the requester. This attribute can only be set if the Multiple Companies feature is enabled (Estate plan and above). Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.' ,
2020-02-18 11:03:48 -08:00
} ,
{
displayName : 'Description' ,
name : 'description' ,
2019-11-08 08:26:09 -08:00
type : 'string' ,
default : '' ,
2020-02-18 11:03:48 -08:00
typeOptions : {
rows : 5 ,
} ,
2022-05-06 14:01:25 -07:00
description : 'HTML content of the ticket' ,
2019-11-08 08:26:09 -08:00
} ,
{
displayName : 'Due By' ,
name : 'dueBy' ,
type : 'dateTime' ,
default : '' ,
2022-05-06 14:01:25 -07:00
description : 'Timestamp that denotes when the ticket is due to be resolved' ,
2019-11-08 08:26:09 -08:00
} ,
{
2022-06-03 10:23:49 -07:00
displayName : 'Email Config ID' ,
2019-11-08 08:26:09 -08:00
name : 'emailConfigId' ,
type : 'number' ,
default : '' ,
2022-08-01 13:47:55 -07:00
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." ,
2019-11-08 08:26:09 -08:00
} ,
{
displayName : 'FR Due By' ,
name : 'frDueBy' ,
type : 'dateTime' ,
default : '' ,
2022-05-06 14:01:25 -07:00
description : 'Timestamp that denotes when the first response is due' ,
2019-11-08 08:26:09 -08:00
} ,
{
2022-06-03 10:23:49 -07:00
displayName : 'Group Name or ID' ,
2019-11-08 08:26:09 -08:00
name : 'group' ,
type : 'options' ,
default : '' ,
typeOptions : {
2020-10-22 06:46:03 -07:00
loadOptionsMethod : 'getGroups' ,
2019-11-08 08:26:09 -08:00
} ,
2022-08-01 13:47:55 -07:00
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. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.' ,
2019-11-08 08:26:09 -08:00
} ,
2020-02-18 11:03:48 -08:00
{
displayName : 'Name' ,
name : 'name' ,
type : 'string' ,
default : '' ,
placeholder : '' ,
description : 'Name of the requester' ,
} ,
2019-11-08 08:26:09 -08:00
{
2022-06-03 10:23:49 -07:00
displayName : 'Product Name or ID' ,
2019-11-08 08:26:09 -08:00
name : 'product' ,
type : 'options' ,
default : '' ,
typeOptions : {
2020-10-22 06:46:03 -07:00
loadOptionsMethod : 'getProducts' ,
2019-11-08 08:26:09 -08:00
} ,
2022-08-01 13:47:55 -07:00
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. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.' ,
2019-11-08 08:26:09 -08:00
} ,
{
2020-02-18 11:03:48 -08:00
displayName : 'Subject' ,
name : 'subject' ,
type : 'string' ,
default : '' ,
placeholder : '' ,
2022-05-06 14:01:25 -07:00
description : 'Subject of the ticket' ,
2020-02-18 11:03:48 -08:00
} ,
{
displayName : 'Tags' ,
name : 'tags' ,
type : 'string' ,
2019-11-08 08:26:09 -08:00
default : '' ,
2022-06-03 10:23:49 -07:00
description : 'Separated by a comma (,) tags that have been associated with the ticket' ,
2020-02-18 11:03:48 -08:00
} ,
{
displayName : 'Type' ,
name : 'type' ,
type : 'options' ,
default : 'Question' ,
2022-08-01 13:47:55 -07:00
description :
'Helps categorize the ticket according to the different kinds of issues your support team deals with' ,
2020-02-18 11:03:48 -08:00
options : [
{
2020-02-21 06:07:03 -08:00
name : 'Feature Request' ,
value : 'Feature Request' ,
2020-02-18 11:03:48 -08:00
} ,
{
name : 'Incident' ,
2020-02-21 06:07:03 -08:00
value : 'Incident' ,
2020-02-18 11:03:48 -08:00
} ,
{
name : 'Problem' ,
2020-02-21 06:07:03 -08:00
value : 'Problem' ,
2020-02-18 11:03:48 -08:00
} ,
{
2020-02-21 06:07:03 -08:00
name : 'Question' ,
value : 'Question' ,
2020-02-18 11:03:48 -08:00
} ,
{
name : 'Refund' ,
2020-02-21 06:07:03 -08:00
value : 'Refund' ,
2020-02-18 11:03:48 -08:00
} ,
2020-10-22 06:46:03 -07:00
] ,
2019-11-08 08:26:09 -08:00
} ,
2020-10-22 06:46:03 -07:00
] ,
2019-11-08 08:26:09 -08:00
} ,
// {
// displayName: 'Custom Fields',
// name: 'customFieldsUi',
// placeholder: 'Add Custom fields',
// type: 'fixedCollection',
// required: false,
// default: '',
// typeOptions: {
// multipleValues: true,
// },
// displayOptions: {
// show: {
// resource: [
// 'ticket'
// ],
// operation: [
// 'create'
// ],
// jsonParameters: [
// false,
// ],
// },
// },
// description: 'Key value pairs containing the names and values of custom fields.',
// options: [
// {
// name: 'customFieldsValues',
// displayName: 'Custom fields',
// values: [
// {
// displayName: 'Key',
// required: false,
// name: 'key',
// type: 'string',
// default: '',
// },
// {
// displayName: 'Value',
// name: 'value',
// type: 'string',
// required: false,
// default: '',
// },
// ],
// },
// ],
// },
// {
// displayName: 'Custom Fields',
// name: 'customFieldsJson',
// type: 'json',
// typeOptions: {
// alwaysOpenEditWindow: true,
// },
// displayOptions: {
// show: {
// resource: [
2020-02-21 06:07:03 -08:00
// 'ticket',
2019-11-08 08:26:09 -08:00
// ],
// operation: [
2020-02-21 06:07:03 -08:00
// 'create',
2019-11-08 08:26:09 -08:00
// ],
// jsonParameters: [
// true,
// ],
// },
// },
// default: '',
// required: false,
// placeholder: `{
2020-02-21 06:07:03 -08:00
// 'gadget': 'Cold Welder',
2019-11-08 08:26:09 -08:00
// }`,
// description: 'Key value pairs containing the names and values of custom fields.',
// },
2020-02-18 11:03:48 -08:00
{
displayName : 'Ticket ID' ,
name : 'ticketId' ,
type : 'string' ,
required : true ,
displayOptions : {
show : {
2022-08-01 13:47:55 -07:00
resource : [ 'ticket' ] ,
operation : [ 'update' ] ,
2020-02-18 11:03:48 -08:00
} ,
} ,
default : '' ,
2019-11-08 08:26:09 -08:00
} ,
2020-02-18 11:03:48 -08:00
{
displayName : 'Update Fields' ,
name : 'updateFields' ,
type : 'collection' ,
placeholder : 'Add Field' ,
default : { } ,
displayOptions : {
show : {
2022-08-01 13:47:55 -07:00
resource : [ 'ticket' ] ,
operation : [ 'update' ] ,
2020-02-18 11:03:48 -08:00
} ,
} ,
options : [
{
2022-06-03 10:23:49 -07:00
displayName : 'Agent Name or ID' ,
2020-02-18 11:03:48 -08:00
name : 'agent' ,
type : 'options' ,
default : '' ,
typeOptions : {
2020-02-21 06:07:03 -08:00
loadOptionsMethod : 'getAgents' ,
2020-02-18 11:03:48 -08:00
} ,
2022-08-01 13:47:55 -07:00
description :
'ID of the agent to whom the ticket has been assigned. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.' ,
2020-02-18 11:03:48 -08:00
} ,
{
displayName : 'CC Emails' ,
name : 'ccEmails' ,
type : 'string' ,
default : '' ,
2022-08-01 13:47:55 -07:00
description :
"Separated by a comma (,) email addresses added in the 'cc' field of the incoming ticket email" ,
2020-02-18 11:03:48 -08:00
} ,
{
2022-06-03 10:23:49 -07:00
displayName : 'Company Name or ID' ,
2020-02-18 11:03:48 -08:00
name : 'company' ,
type : 'options' ,
default : '' ,
typeOptions : {
2020-02-21 06:07:03 -08:00
loadOptionsMethod : 'getCompanies' ,
2020-02-18 11:03:48 -08:00
} ,
2022-08-01 13:47:55 -07:00
description :
'Company ID of the requester. This attribute can only be set if the Multiple Companies feature is enabled (Estate plan and above). Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.' ,
2020-02-18 11:03:48 -08:00
} ,
{
displayName : 'Due By' ,
name : 'dueBy' ,
type : 'dateTime' ,
default : '' ,
2022-05-06 14:01:25 -07:00
description : 'Timestamp that denotes when the ticket is due to be resolved' ,
2020-02-18 11:03:48 -08:00
} ,
{
2022-06-03 10:23:49 -07:00
displayName : 'Email Config ID' ,
2020-02-18 11:03:48 -08:00
name : 'emailConfigId' ,
type : 'number' ,
default : '' ,
2022-08-01 13:47:55 -07:00
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." ,
2020-02-18 11:03:48 -08:00
} ,
{
displayName : 'FR Due By' ,
name : 'frDueBy' ,
type : 'dateTime' ,
default : '' ,
2022-05-06 14:01:25 -07:00
description : 'Timestamp that denotes when the first response is due' ,
2020-02-18 11:03:48 -08:00
} ,
{
2022-06-03 10:23:49 -07:00
displayName : 'Group Name or ID' ,
2020-02-18 11:03:48 -08:00
name : 'group' ,
type : 'options' ,
default : '' ,
typeOptions : {
2020-02-21 06:07:03 -08:00
loadOptionsMethod : 'getGroups' ,
2020-02-18 11:03:48 -08:00
} ,
2022-08-01 13:47:55 -07:00
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. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.' ,
2020-02-18 11:03:48 -08:00
} ,
{
displayName : 'Name' ,
name : 'name' ,
type : 'string' ,
default : '' ,
placeholder : '' ,
description : 'Name of the requester' ,
} ,
{
2022-06-03 10:23:49 -07:00
displayName : 'Product Name or ID' ,
2020-02-18 11:03:48 -08:00
name : 'product' ,
type : 'options' ,
default : '' ,
typeOptions : {
2020-02-21 06:07:03 -08:00
loadOptionsMethod : 'getProducts' ,
2020-02-18 11:03:48 -08:00
} ,
2022-08-01 13:47:55 -07:00
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. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.' ,
2020-02-18 11:03:48 -08:00
} ,
{
displayName : 'Priority' ,
name : 'priority' ,
type : 'options' ,
options : [
{
name : 'Low' ,
value : 'low' ,
} ,
{
name : 'Medium' ,
value : 'medium' ,
} ,
{
name : 'High' ,
value : 'high' ,
} ,
{
name : 'Urgent' ,
value : 'urgent' ,
2020-10-22 06:46:03 -07:00
} ,
2020-02-18 11:03:48 -08:00
] ,
default : 'low' ,
} ,
{
displayName : 'Requester Identification' ,
name : 'requester' ,
type : 'options' ,
options : [
{
name : 'Email' ,
value : 'email' ,
2022-08-01 13:47:55 -07:00
description :
'Email address of the requester. If no contact exists with this email address in Freshdesk, it will be added as a new contact.' ,
2020-02-18 11:03:48 -08:00
} ,
{
2022-05-20 14:47:24 -07:00
name : 'Facebook ID' ,
2020-02-18 11:03:48 -08:00
value : 'facebookId' ,
2022-08-01 13:47:55 -07:00
description :
'Facebook ID of the requester. If no contact exists with this facebook_id, then a new contact will be created.' ,
2020-02-18 11:03:48 -08:00
} ,
{
name : 'Phone' ,
value : 'phone' ,
2022-08-01 13:47:55 -07:00
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.' ,
2020-02-18 11:03:48 -08:00
} ,
2020-02-21 06:07:03 -08:00
{
2022-05-20 14:47:24 -07:00
name : 'Requester ID' ,
2020-02-21 06:07:03 -08:00
value : 'requesterId' ,
2022-08-01 13:47:55 -07:00
description :
"User ID of the requester. For existing contacts, the requester_id can be passed instead of the requester's email." ,
2020-02-21 06:07:03 -08:00
} ,
2020-02-18 11:03:48 -08:00
{
2022-05-20 14:47:24 -07:00
name : 'Twitter ID' ,
2020-02-18 11:03:48 -08:00
value : 'twitterId' ,
2022-08-01 13:47:55 -07:00
description :
'Twitter handle of the requester. If no contact exists with this handle in Freshdesk, it will be added as a new contact.' ,
2020-02-18 11:03:48 -08:00
} ,
{
2022-05-20 14:47:24 -07:00
name : 'Unique External ID' ,
2020-02-18 11:03:48 -08:00
value : 'uniqueExternalId' ,
2022-08-01 13:47:55 -07:00
description :
'External ID of the requester. If no contact exists with this external ID in Freshdesk, they will be added as a new contact.' ,
2020-02-18 11:03:48 -08:00
} ,
] ,
default : 'requesterId' ,
} ,
{
displayName : 'Requester Value' ,
name : 'requesterIdentificationValue' ,
type : 'string' ,
default : '' ,
2022-05-06 14:01:25 -07:00
description : 'Value of the identification selected' ,
2020-02-18 11:03:48 -08:00
} ,
{
displayName : 'Status' ,
name : 'status' ,
type : 'options' ,
options : [
{
name : 'Open' ,
value : 'open' ,
} ,
{
name : 'Pending' ,
value : 'pending' ,
} ,
{
name : 'Resolved' ,
value : 'resolved' ,
} ,
{
name : 'Closed' ,
value : 'closed' ,
2020-10-22 06:46:03 -07:00
} ,
2020-02-18 11:03:48 -08:00
] ,
default : 'pending' ,
} ,
{
displayName : 'Source' ,
name : 'source' ,
type : 'options' ,
options : [
2020-02-21 06:07:03 -08:00
{
name : 'Chat' ,
value : 'chat' ,
} ,
2020-02-18 11:03:48 -08:00
{
name : 'Email' ,
value : 'email' ,
} ,
{
2020-02-21 06:07:03 -08:00
name : 'Feedback Widget' ,
value : 'feedbackWidget' ,
2020-02-18 11:03:48 -08:00
} ,
{
2020-02-21 06:07:03 -08:00
name : 'Mobihelp' ,
value : 'mobileHelp' ,
2020-02-18 11:03:48 -08:00
} ,
2020-02-21 06:07:03 -08:00
2020-02-18 11:03:48 -08:00
{
2020-02-21 06:07:03 -08:00
name : 'Outbound Email' ,
value : 'OutboundEmail' ,
2020-02-18 11:03:48 -08:00
} ,
{
2020-02-21 06:07:03 -08:00
name : 'Phone' ,
value : 'phone' ,
2020-02-18 11:03:48 -08:00
} ,
{
2020-02-21 06:07:03 -08:00
name : 'Portal' ,
value : 'portal' ,
2020-02-18 11:03:48 -08:00
} ,
] ,
default : 'portal' ,
2022-05-06 14:01:25 -07:00
description : 'The channel through which the ticket was created' ,
2020-02-18 11:03:48 -08:00
} ,
{
displayName : 'Tags' ,
name : 'tags' ,
type : 'string' ,
default : '' ,
2022-06-03 10:23:49 -07:00
description : 'Separated by a comma (,) tags that have been associated with the ticket' ,
2020-02-18 11:03:48 -08:00
} ,
{
displayName : 'Type' ,
name : 'type' ,
type : 'options' ,
default : 'Question' ,
2022-08-01 13:47:55 -07:00
description :
'Helps categorize the ticket according to the different kinds of issues your support team deals with' ,
2020-02-18 11:03:48 -08:00
options : [
{
2020-02-21 06:07:03 -08:00
name : 'Feature Request' ,
2020-10-22 06:46:03 -07:00
value : 'Feature Request' ,
2020-02-18 11:03:48 -08:00
} ,
{
name : 'Incident' ,
2020-10-22 06:46:03 -07:00
value : 'Incident' ,
2020-02-18 11:03:48 -08:00
} ,
{
name : 'Problem' ,
2020-10-22 06:46:03 -07:00
value : 'Problem' ,
2020-02-18 11:03:48 -08:00
} ,
{
2020-02-21 06:07:03 -08:00
name : 'Question' ,
2020-10-22 06:46:03 -07:00
value : 'Question' ,
2020-02-18 11:03:48 -08:00
} ,
{
name : 'Refund' ,
2020-10-22 06:46:03 -07:00
value : 'Refund' ,
2020-02-18 11:03:48 -08:00
} ,
2020-10-22 06:46:03 -07:00
] ,
2020-02-18 11:03:48 -08:00
} ,
2020-10-22 06:46:03 -07:00
] ,
2020-02-18 11:03:48 -08:00
} ,
{
displayName : 'Ticket ID' ,
name : 'ticketId' ,
type : 'string' ,
required : true ,
displayOptions : {
show : {
2022-08-01 13:47:55 -07:00
resource : [ 'ticket' ] ,
operation : [ 'get' ] ,
2020-02-18 11:03:48 -08:00
} ,
} ,
default : '' ,
} ,
{
displayName : 'Return All' ,
name : 'returnAll' ,
type : 'boolean' ,
displayOptions : {
show : {
2022-08-01 13:47:55 -07:00
resource : [ 'ticket' ] ,
operation : [ 'getAll' ] ,
2020-02-18 11:03:48 -08:00
} ,
} ,
default : false ,
2022-05-06 14:01:25 -07:00
description : 'Whether to return all results or only up to a given limit' ,
2020-02-18 11:03:48 -08:00
} ,
{
displayName : 'Limit' ,
name : 'limit' ,
type : 'number' ,
displayOptions : {
show : {
2022-08-01 13:47:55 -07:00
resource : [ 'ticket' ] ,
operation : [ 'getAll' ] ,
returnAll : [ false ] ,
2020-02-18 11:03:48 -08:00
} ,
} ,
typeOptions : {
minValue : 1 ,
maxValue : 10 ,
} ,
default : 5 ,
2022-05-06 14:01:25 -07:00
description : 'Max number of results to return' ,
2020-02-18 11:03:48 -08:00
} ,
{
displayName : 'Options' ,
name : 'options' ,
type : 'collection' ,
2024-07-29 05:27:23 -07:00
placeholder : 'Add option' ,
2020-02-18 11:03:48 -08:00
default : { } ,
displayOptions : {
show : {
2022-08-01 13:47:55 -07:00
resource : [ 'ticket' ] ,
operation : [ 'getAll' ] ,
2020-02-18 11:03:48 -08:00
} ,
} ,
options : [
{
2020-02-21 06:07:03 -08:00
displayName : 'Company ID' ,
name : 'companyId' ,
type : 'string' ,
default : '' ,
} ,
{
displayName : 'Include' ,
name : 'include' ,
type : 'multiOptions' ,
2020-02-18 11:03:48 -08:00
options : [
{
2020-02-21 06:07:03 -08:00
name : 'Company' ,
value : 'company' ,
2020-02-18 11:03:48 -08:00
} ,
{
2020-02-21 06:07:03 -08:00
name : 'Description' ,
value : 'description' ,
2020-02-18 11:03:48 -08:00
} ,
{
2020-02-21 06:07:03 -08:00
name : 'Requester' ,
value : 'requester' ,
} ,
{
name : 'Stats' ,
value : 'stats' ,
2020-02-18 11:03:48 -08:00
} ,
] ,
2020-02-21 06:07:03 -08:00
default : [ ] ,
2020-02-18 11:03:48 -08:00
} ,
{
displayName : 'Order' ,
name : 'order' ,
type : 'options' ,
options : [
{
name : 'ASC' ,
value : 'asc' ,
} ,
{
name : 'DESC' ,
value : 'desc' ,
} ,
] ,
default : 'desc' ,
2022-05-06 14:01:25 -07:00
description : 'Order sort attribute ascending or descending' ,
2020-02-18 11:03:48 -08:00
} ,
{
2020-02-21 06:07:03 -08:00
displayName : 'Order By' ,
name : 'orderBy' ,
type : 'options' ,
options : [
{
name : 'Created At' ,
value : 'createdAt' ,
} ,
{
name : 'Due By' ,
value : 'dueBy' ,
} ,
{
name : 'Updated At' ,
value : 'updatedAt' ,
} ,
] ,
2020-02-18 11:03:48 -08:00
default : '' ,
2022-05-06 14:01:25 -07:00
description : 'Sort collection by object attribute' ,
2020-02-18 11:03:48 -08:00
} ,
{
displayName : 'Requester Email' ,
name : 'requesterEmail' ,
type : 'string' ,
default : '' ,
} ,
{
2020-02-21 06:07:03 -08:00
displayName : 'Requester ID' ,
name : 'requesterId' ,
2020-02-18 11:03:48 -08:00
type : 'string' ,
default : '' ,
} ,
{
displayName : 'Updated Since' ,
name : 'updatedSince' ,
type : 'dateTime' ,
default : '' ,
} ,
2020-10-22 06:46:03 -07:00
] ,
2020-02-18 11:03:48 -08:00
} ,
{
displayName : 'Ticket ID' ,
name : 'ticketId' ,
type : 'string' ,
required : true ,
displayOptions : {
show : {
2022-08-01 13:47:55 -07:00
resource : [ 'ticket' ] ,
operation : [ 'delete' ] ,
2020-02-18 11:03:48 -08:00
} ,
} ,
default : '' ,
} ,
2020-09-10 12:56:15 -07:00
// CONTACTS
. . . contactOperations ,
. . . contactFields ,
2020-10-22 06:46:03 -07:00
] ,
2020-02-18 11:03:48 -08:00
} ;
2019-11-10 03:33:23 -08:00
2020-02-18 11:03:48 -08:00
methods = {
loadOptions : {
2023-04-19 07:00:49 -07:00
// Get all the agents to display them to user so that they can
2020-02-18 11:03:48 -08:00
// select them easily
async getAgents ( this : ILoadOptionsFunctions ) : Promise < INodePropertyOptions [ ] > {
const returnData : INodePropertyOptions [ ] = [ ] ;
2020-02-21 06:07:03 -08:00
const agents = await freshdeskApiRequest . call ( this , 'GET' , '/agents' ) ;
2020-02-18 11:03:48 -08:00
for ( const agent of agents ) {
const agentName = agent . contact . name ;
const agentId = agent . id ;
2019-11-08 08:26:09 -08:00
2020-02-18 11:03:48 -08:00
returnData . push ( {
name : agentName ,
value : agentId ,
} ) ;
2019-11-08 08:26:09 -08:00
}
2020-02-18 11:03:48 -08:00
return returnData ;
} ,
2019-11-08 08:26:09 -08:00
2023-04-19 07:00:49 -07:00
// Get all the groups to display them to user so that they can
2020-02-18 11:03:48 -08:00
// select them easily
async getGroups ( this : ILoadOptionsFunctions ) : Promise < INodePropertyOptions [ ] > {
const returnData : INodePropertyOptions [ ] = [ ] ;
2020-02-21 06:07:03 -08:00
const groups = await freshdeskApiRequest . call ( this , 'GET' , '/groups' ) ;
2020-02-18 11:03:48 -08:00
for ( const group of groups ) {
const groupName = group . name ;
const groupId = group . id ;
2019-11-08 08:26:09 -08:00
2020-02-18 11:03:48 -08:00
returnData . push ( {
name : groupName ,
value : groupId ,
} ) ;
2019-11-08 08:26:09 -08:00
}
2020-02-18 11:03:48 -08:00
return returnData ;
} ,
2019-11-08 08:26:09 -08:00
2023-04-19 07:00:49 -07:00
// Get all the products to display them to user so that they can
2020-02-18 11:03:48 -08:00
// select them easily
async getProducts ( this : ILoadOptionsFunctions ) : Promise < INodePropertyOptions [ ] > {
const returnData : INodePropertyOptions [ ] = [ ] ;
2020-02-21 06:07:03 -08:00
const products = await freshdeskApiRequest . call ( this , 'GET' , '/products' ) ;
2020-02-18 11:03:48 -08:00
for ( const product of products ) {
const productName = product . name ;
const productId = product . id ;
2019-11-08 08:26:09 -08:00
2020-02-18 11:03:48 -08:00
returnData . push ( {
name : productName ,
value : productId ,
} ) ;
2019-11-08 08:26:09 -08:00
}
2020-02-18 11:03:48 -08:00
return returnData ;
} ,
2019-11-08 08:26:09 -08:00
2023-04-19 07:00:49 -07:00
// Get all the companies to display them to user so that they can
2020-02-18 11:03:48 -08:00
// select them easily
async getCompanies ( this : ILoadOptionsFunctions ) : Promise < INodePropertyOptions [ ] > {
const returnData : INodePropertyOptions [ ] = [ ] ;
2020-02-21 06:07:03 -08:00
const companies = await freshdeskApiRequest . call ( this , 'GET' , '/companies' ) ;
2020-02-18 11:03:48 -08:00
for ( const company of companies ) {
const companyName = company . name ;
const companyId = company . id ;
2019-11-08 08:26:09 -08:00
2020-02-18 11:03:48 -08:00
returnData . push ( {
name : companyName ,
value : companyId ,
} ) ;
2019-11-08 08:26:09 -08:00
}
2020-02-18 11:03:48 -08:00
return returnData ;
} ,
} ,
} ;
2019-11-10 03:33:23 -08:00
2020-02-18 11:03:48 -08:00
async execute ( this : IExecuteFunctions ) : Promise < INodeExecutionData [ ] [ ] > {
const items = this . getInputData ( ) ;
2022-08-30 08:55:33 -07:00
const returnData : INodeExecutionData [ ] = [ ] ;
2020-02-18 11:03:48 -08:00
let responseData ;
const qs : IDataObject = { } ;
2022-12-02 03:53:59 -08:00
const resource = this . getNodeParameter ( 'resource' , 0 ) ;
const operation = this . getNodeParameter ( 'operation' , 0 ) ;
2020-02-21 06:07:03 -08:00
for ( let i = 0 ; i < items . length ; i ++ ) {
2021-07-19 23:58:54 -07:00
try {
if ( resource === 'ticket' ) {
//https://developers.freshdesk.com/api/#create_ticket
if ( operation === 'create' ) {
const requester = this . getNodeParameter ( 'requester' , i ) as string ;
const value = this . getNodeParameter ( 'requesterIdentificationValue' , i ) as string ;
const status = this . getNodeParameter ( 'status' , i ) as string ;
const priority = this . getNodeParameter ( 'priority' , i ) as string ;
const source = this . getNodeParameter ( 'source' , i ) as string ;
2022-11-18 07:29:44 -08:00
const options = this . getNodeParameter ( 'options' , i ) ;
2021-07-19 23:58:54 -07:00
//const jsonActive = this.getNodeParameter('jsonParameters') as boolean;
const body : ICreateTicketBody = {
// @ts-ignore
status : Status [ capitalize ( status ) ] ,
// @ts-ignore
priority : Priority [ capitalize ( priority ) ] ,
// @ts-ignore
source : Source [ capitalize ( source ) ] ,
} ;
2019-11-08 08:26:09 -08:00
2021-07-19 23:58:54 -07:00
if ( requester === 'requesterId' ) {
// @ts-ignore
if ( isNaN ( value ) ) {
2022-08-01 13:47:55 -07:00
throw new NodeOperationError ( this . getNode ( ) , 'Requester Id must be a number' , {
itemIndex : i ,
} ) ;
2021-07-19 23:58:54 -07:00
}
body . requester_id = parseInt ( value , 10 ) ;
} else if ( requester === 'email' ) {
body . email = value ;
} else if ( requester === 'facebookId' ) {
body . facebook_id = value ;
} else if ( requester === 'phone' ) {
body . phone = value ;
} else if ( requester === 'twitterId' ) {
body . twitter_id = value ;
} else if ( requester === 'uniqueExternalId' ) {
body . unique_external_id = value ;
2020-02-18 11:03:48 -08:00
}
2019-11-08 08:26:09 -08:00
2021-07-19 23:58:54 -07:00
// if (!jsonActive) {
// const customFieldsUi = this.getNodeParameter('customFieldsUi') as IDataObject;
// if (Object.keys(customFieldsUi).length > 0) {
// const aux: IDataObject = {};
// // @ts-ignore
// customFieldsUi.customFieldsValues.forEach( o => {
// aux[`${o.key}`] = o.value;
// return aux;
// });
// body.custom_fields = aux;
// } else {
// body.custom_fields = validateJSON(this.getNodeParameter('customFielsJson') as string);
// }
2019-11-08 08:26:09 -08:00
2021-07-19 23:58:54 -07:00
if ( options . name ) {
body . name = options . name as string ;
}
if ( options . subject ) {
body . subject = options . subject as string ;
} else {
body . subject = 'null' ;
}
if ( options . type ) {
body . type = options . type as string ;
}
if ( options . description ) {
body . description = options . description as string ;
} else {
body . description = 'null' ;
}
if ( options . agent ) {
body . responder_id = options . agent as number ;
}
if ( options . company ) {
body . company_id = options . company as number ;
}
if ( options . product ) {
body . product_id = options . product as number ;
}
if ( options . group ) {
body . group_id = options . group as number ;
}
if ( options . frDueBy ) {
body . fr_due_by = options . frDueBy as string ;
}
if ( options . emailConfigId ) {
body . email_config_id = options . emailConfigId as number ;
}
if ( options . dueBy ) {
body . due_by = options . dueBy as string ;
}
if ( options . tags ) {
body . tags = ( options . tags as string ) . split ( ',' ) as [ string ] ;
}
if ( options . ccEmails ) {
body . cc_emails = ( options . ccEmails as string ) . split ( ',' ) as [ string ] ;
}
responseData = await freshdeskApiRequest . call ( this , 'POST' , '/tickets' , body ) ;
2020-02-18 11:03:48 -08:00
}
2021-07-19 23:58:54 -07:00
//https://developers.freshdesk.com/api/#update_ticket
if ( operation === 'update' ) {
const ticketId = this . getNodeParameter ( 'ticketId' , i ) as string ;
2022-11-18 07:29:44 -08:00
const updateFields = this . getNodeParameter ( 'updateFields' , i ) ;
2021-07-19 23:58:54 -07:00
const body : ICreateTicketBody = { } ;
2019-11-10 03:33:23 -08:00
2021-07-19 23:58:54 -07:00
if ( updateFields . requester ) {
const value = updateFields . requesterIdentificationValue as string ;
if ( updateFields . requester === 'requesterId' ) {
// @ts-ignore
if ( isNaN ( parseInt ( value , 10 ) ) ) {
2022-08-01 13:47:55 -07:00
throw new NodeOperationError ( this . getNode ( ) , 'Requester Id must be a number' , {
itemIndex : i ,
} ) ;
2021-07-19 23:58:54 -07:00
}
2022-12-02 12:54:28 -08:00
body . requester_id = parseInt ( value , 10 ) ;
2021-07-19 23:58:54 -07:00
} else if ( updateFields . requester === 'email' ) {
2022-12-02 12:54:28 -08:00
body . email = value ;
2021-07-19 23:58:54 -07:00
} else if ( updateFields . requester === 'facebookId' ) {
2022-12-02 12:54:28 -08:00
body . facebook_id = value ;
2021-07-19 23:58:54 -07:00
} else if ( updateFields . requester === 'phone' ) {
2022-12-02 12:54:28 -08:00
body . phone = value ;
2021-07-19 23:58:54 -07:00
} else if ( updateFields . requester === 'twitterId' ) {
2022-12-02 12:54:28 -08:00
body . twitter_id = value ;
2021-07-19 23:58:54 -07:00
} else if ( updateFields . requester === 'uniqueExternalId' ) {
2022-12-02 12:54:28 -08:00
body . unique_external_id = value ;
2020-02-18 11:03:48 -08:00
}
}
2021-07-19 23:58:54 -07:00
if ( updateFields . status ) {
//@ts-ignore
body . status = Status [ capitalize ( updateFields . status ) ] ;
}
if ( updateFields . priority ) {
//@ts-ignore
body . priority = Priority [ capitalize ( updateFields . priority ) ] ;
}
if ( updateFields . source ) {
//@ts-ignore
body . source = Source [ capitalize ( updateFields . source ) ] ;
}
if ( updateFields . name ) {
body . name = updateFields . name as string ;
}
if ( updateFields . type ) {
body . type = updateFields . type as string ;
}
if ( updateFields . agent ) {
body . responder_id = updateFields . agent as number ;
}
if ( updateFields . company ) {
body . company_id = updateFields . company as number ;
}
if ( updateFields . product ) {
body . product_id = updateFields . product as number ;
}
if ( updateFields . group ) {
body . group_id = updateFields . group as number ;
}
if ( updateFields . frDueBy ) {
body . fr_due_by = updateFields . frDueBy as string ;
}
if ( updateFields . emailConfigId ) {
body . email_config_id = updateFields . emailConfigId as number ;
}
if ( updateFields . dueBy ) {
body . due_by = updateFields . dueBy as string ;
}
if ( updateFields . tags ) {
body . tags = ( updateFields . tags as string ) . split ( ',' ) as [ string ] ;
}
if ( updateFields . ccEmails ) {
body . cc_emails = ( updateFields . ccEmails as string ) . split ( ',' ) as [ string ] ;
}
2022-08-01 13:47:55 -07:00
responseData = await freshdeskApiRequest . call (
this ,
'PUT' ,
` /tickets/ ${ ticketId } ` ,
body ,
) ;
2020-02-18 11:03:48 -08:00
}
2021-07-19 23:58:54 -07:00
//https://developers.freshdesk.com/api/#view_a_ticket
if ( operation === 'get' ) {
const ticketId = this . getNodeParameter ( 'ticketId' , i ) as string ;
responseData = await freshdeskApiRequest . call ( this , 'GET' , ` /tickets/ ${ ticketId } ` ) ;
2020-02-18 11:03:48 -08:00
}
2021-07-19 23:58:54 -07:00
//https://developers.freshdesk.com/api/#list_all_tickets
if ( operation === 'getAll' ) {
2022-11-18 05:31:38 -08:00
const returnAll = this . getNodeParameter ( 'returnAll' , i ) ;
2022-11-18 07:29:44 -08:00
const options = this . getNodeParameter ( 'options' , i ) ;
2021-07-19 23:58:54 -07:00
if ( options . requesterId ) {
qs . requester_id = options . requesterId as string ;
}
if ( options . requesterEmail ) {
qs . email = options . requesterEmail as string ;
}
if ( options . companyId ) {
qs . company_id = options . companyId as string ;
}
if ( options . updatedSince ) {
qs . updated_since = options . updatedSince as string ;
}
if ( options . orderBy ) {
qs . order_by = options . orderBy as string ;
}
if ( options . order ) {
qs . order_type = options . order as string ;
}
if ( options . include ) {
if ( ( options . include as string [ ] ) . length !== 0 ) {
qs . include = ( options . include as string [ ] ) . join ( ',' ) ;
}
}
2022-12-02 12:54:28 -08:00
if ( returnAll ) {
2022-08-01 13:47:55 -07:00
responseData = await freshdeskApiRequestAllItems . call (
this ,
'GET' ,
'/tickets' ,
{ } ,
qs ,
) ;
2021-07-19 23:58:54 -07:00
} else {
2022-11-18 06:26:22 -08:00
qs . per_page = this . getNodeParameter ( 'limit' , i ) ;
2021-07-19 23:58:54 -07:00
responseData = await freshdeskApiRequest . call ( this , 'GET' , '/tickets' , { } , qs ) ;
2020-02-18 11:03:48 -08:00
}
}
2021-07-19 23:58:54 -07:00
//https://developers.freshdesk.com/api/#delete_a_ticket
if ( operation === 'delete' ) {
const ticketId = this . getNodeParameter ( 'ticketId' , i ) as string ;
responseData = await freshdeskApiRequest . call ( this , 'DELETE' , ` /tickets/ ${ ticketId } ` ) ;
2020-02-18 11:03:48 -08:00
}
2021-07-19 23:58:54 -07:00
} else if ( resource === 'contact' ) {
//https://developers.freshdesk.com/api/#create_contact
if ( operation === 'create' ) {
const name = this . getNodeParameter ( 'name' , i ) as string ;
const email = this . getNodeParameter ( 'email' , i ) as string ;
2022-12-02 12:54:28 -08:00
const additionalFields = this . getNodeParameter ( 'additionalFields' , i , { } ) ;
2020-09-10 12:56:15 -07:00
2021-07-19 23:58:54 -07:00
if ( additionalFields . customFields ) {
2022-08-01 13:47:55 -07:00
const metadata = ( additionalFields . customFields as IDataObject )
. customField as IDataObject [ ] ;
2021-07-19 23:58:54 -07:00
additionalFields . custom_fields = { } ;
for ( const data of metadata ) {
//@ts-ignore
additionalFields . custom_fields [ data . name as string ] = data . value ;
}
delete additionalFields . customFields ;
2020-09-10 12:56:15 -07:00
}
2021-07-19 23:58:54 -07:00
const body : ICreateContactBody = additionalFields ;
body . name = name ;
if ( email ) {
body . email = email ;
}
responseData = await freshdeskApiRequest . call ( this , 'POST' , '/contacts' , body ) ;
2022-08-01 13:47:55 -07:00
//https://developers.freshdesk.com/api/#delete_contact
2021-07-19 23:58:54 -07:00
} else if ( operation === 'delete' ) {
const contactId = this . getNodeParameter ( 'contactId' , i ) as string ;
2022-08-01 13:47:55 -07:00
responseData = await freshdeskApiRequest . call (
this ,
'DELETE' ,
` /contacts/ ${ contactId } ` ,
{ } ,
) ;
2021-07-19 23:58:54 -07:00
} else if ( operation === 'get' ) {
const contactId = this . getNodeParameter ( 'contactId' , i ) as string ;
2022-08-01 13:47:55 -07:00
responseData = await freshdeskApiRequest . call (
this ,
'GET' ,
` /contacts/ ${ contactId } ` ,
{ } ,
) ;
//https://developers.freshdesk.com/api/#list_all_contacts
2021-07-19 23:58:54 -07:00
} else if ( operation === 'getAll' ) {
2022-12-02 12:54:28 -08:00
const filters = this . getNodeParameter ( 'filters' , i , { } ) ;
responseData = await freshdeskApiRequest . call ( this , 'GET' , '/contacts' , { } , filters ) ;
2022-08-01 13:47:55 -07:00
//https://developers.freshdesk.com/api/#update_contact
2021-07-19 23:58:54 -07:00
} else if ( operation === 'update' ) {
const contactId = this . getNodeParameter ( 'contactId' , i ) as string ;
2022-12-02 12:54:28 -08:00
const additionalFields = this . getNodeParameter ( 'additionalFields' , i , { } ) ;
2020-09-10 12:56:15 -07:00
2021-07-19 23:58:54 -07:00
if ( additionalFields . customFields ) {
2022-08-01 13:47:55 -07:00
const metadata = ( additionalFields . customFields as IDataObject )
. customField as IDataObject [ ] ;
2021-07-19 23:58:54 -07:00
additionalFields . custom_fields = { } ;
for ( const data of metadata ) {
//@ts-ignore
additionalFields . custom_fields [ data . name as string ] = data . value ;
}
delete additionalFields . customFields ;
2020-09-10 12:56:15 -07:00
}
2021-07-19 23:58:54 -07:00
const body : ICreateContactBody = additionalFields ;
2022-08-01 13:47:55 -07:00
responseData = await freshdeskApiRequest . call (
this ,
'PUT' ,
` /contacts/ ${ contactId } ` ,
body ,
) ;
2021-07-19 23:58:54 -07:00
}
2020-09-10 12:56:15 -07:00
}
2022-08-30 08:55:33 -07:00
if ( ! Array . isArray ( responseData ) && responseData === undefined ) {
responseData = {
success : true ,
} ;
2021-07-19 23:58:54 -07:00
}
2022-08-30 08:55:33 -07:00
const executionData = this . helpers . constructExecutionMetaData (
2023-02-27 19:39:43 -08:00
this . helpers . returnJsonArray ( responseData as IDataObject [ ] ) ,
2022-08-30 08:55:33 -07:00
{ itemData : { item : i } } ,
) ;
returnData . push ( . . . executionData ) ;
2021-07-19 23:58:54 -07:00
} catch ( error ) {
2024-08-30 00:59:30 -07:00
if ( this . continueOnFail ( ) ) {
2022-08-30 08:55:33 -07:00
const executionErrorData = this . helpers . constructExecutionMetaData (
this . helpers . returnJsonArray ( { error : error.message } ) ,
{ itemData : { item : i } } ,
) ;
returnData . push ( . . . executionErrorData ) ;
2021-07-19 23:58:54 -07:00
continue ;
}
throw error ;
2019-11-08 08:26:09 -08:00
}
}
2023-09-05 03:59:02 -07:00
return [ returnData ] ;
2019-11-10 14:14:36 -08:00
}
2019-11-08 08:26:09 -08:00
}