mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
✨ Add support for suspended tickets to Zendesk node (#2297)
* Added Suspended Tickets (Delete, List, Get, Recover) * Added Search option to Active tickets * Added internal note, public reply and assignee email options to active ticket updates * ⚡ Small improvements to #2296 * 🐛 Fix issue with pagination * ⚡ Improvements Co-authored-by: Jonathan <jonathan.bennetts@gmail.com>
This commit is contained in:
@@ -42,7 +42,7 @@ import {
|
||||
import {
|
||||
IComment,
|
||||
ITicket,
|
||||
} from './TicketInterface';
|
||||
} from './TicketInterface';
|
||||
|
||||
export class Zendesk implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
@@ -99,7 +99,7 @@ export class Zendesk implements INodeType {
|
||||
},
|
||||
],
|
||||
default: 'apiToken',
|
||||
description: 'The resource to operate on.',
|
||||
description: 'The resource to operate on',
|
||||
},
|
||||
{
|
||||
displayName: 'Resource',
|
||||
@@ -109,7 +109,7 @@ export class Zendesk implements INodeType {
|
||||
{
|
||||
name: 'Ticket',
|
||||
value: 'ticket',
|
||||
description: 'Tickets are the means through which your end users (customers) communicate with agents in Zendesk Support.',
|
||||
description: 'Tickets are the means through which your end users (customers) communicate with agents in Zendesk Support',
|
||||
},
|
||||
{
|
||||
name: 'Ticket Field',
|
||||
@@ -128,7 +128,7 @@ export class Zendesk implements INodeType {
|
||||
},
|
||||
],
|
||||
default: 'ticket',
|
||||
description: 'Resource to consume.',
|
||||
description: 'Resource to consume',
|
||||
},
|
||||
// TICKET
|
||||
...ticketOperations,
|
||||
@@ -286,12 +286,12 @@ export class Zendesk implements INodeType {
|
||||
body: description,
|
||||
};
|
||||
const body: ITicket = {
|
||||
comment,
|
||||
comment,
|
||||
};
|
||||
if (jsonParameters) {
|
||||
const additionalFieldsJson = this.getNodeParameter('additionalFieldsJson', i) as string;
|
||||
|
||||
if (additionalFieldsJson !== '' ) {
|
||||
if (additionalFieldsJson !== '') {
|
||||
|
||||
if (validateJSON(additionalFieldsJson) !== undefined) {
|
||||
|
||||
@@ -343,7 +343,7 @@ export class Zendesk implements INodeType {
|
||||
if (jsonParameters) {
|
||||
const updateFieldsJson = this.getNodeParameter('updateFieldsJson', i) as string;
|
||||
|
||||
if (updateFieldsJson !== '' ) {
|
||||
if (updateFieldsJson !== '') {
|
||||
|
||||
if (validateJSON(updateFieldsJson) !== undefined) {
|
||||
|
||||
@@ -382,44 +382,87 @@ export class Zendesk implements INodeType {
|
||||
if (updateFields.customFieldsUi) {
|
||||
body.custom_fields = (updateFields.customFieldsUi as IDataObject).customFieldsValues as IDataObject[];
|
||||
}
|
||||
if (updateFields.assigneeEmail) {
|
||||
body.assignee_email = updateFields.assigneeEmail as string;
|
||||
}
|
||||
if (updateFields.internalNote) {
|
||||
const comment: IComment = {
|
||||
html_body: updateFields.internalNote as string,
|
||||
public: false,
|
||||
};
|
||||
body.comment = comment;
|
||||
}
|
||||
|
||||
if (updateFields.publicReply) {
|
||||
const comment: IComment = {
|
||||
body: updateFields.publicReply as string,
|
||||
public: true,
|
||||
};
|
||||
body.comment = comment;
|
||||
}
|
||||
|
||||
}
|
||||
responseData = await zendeskApiRequest.call(this, 'PUT', `/tickets/${ticketId}`, { ticket: body });
|
||||
responseData = responseData.ticket;
|
||||
}
|
||||
//https://developer.zendesk.com/rest_api/docs/support/tickets#show-ticket
|
||||
//https://developer.zendesk.com/api-reference/ticketing/tickets/suspended_tickets/#show-suspended-ticket
|
||||
if (operation === 'get') {
|
||||
const ticketType = this.getNodeParameter('ticketType', i) as string;
|
||||
const ticketId = this.getNodeParameter('id', i) as string;
|
||||
responseData = await zendeskApiRequest.call(this, 'GET', `/tickets/${ticketId}`, {});
|
||||
responseData = responseData.ticket;
|
||||
const endpoint = (ticketType === 'regular') ? `/tickets/${ticketId}` : `/suspended_tickets/${ticketId}`;
|
||||
responseData = await zendeskApiRequest.call(this, 'GET', endpoint, {});
|
||||
responseData = responseData.ticket || responseData.suspended_ticket;
|
||||
}
|
||||
//https://developer.zendesk.com/rest_api/docs/support/search#list-search-results
|
||||
//https://developer.zendesk.com/api-reference/ticketing/tickets/suspended_tickets/#list-suspended-tickets
|
||||
if (operation === 'getAll') {
|
||||
const ticketType = this.getNodeParameter('ticketType', i) as string;
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
const options = this.getNodeParameter('options', i) as IDataObject;
|
||||
qs.query = 'type:ticket';
|
||||
if (options.query) {
|
||||
qs.query += ` ${options.query}`;
|
||||
}
|
||||
if (options.status) {
|
||||
qs.query += ` status:${options.status}`;
|
||||
}
|
||||
if (options.group) {
|
||||
qs.query += ` group:${options.group}`;
|
||||
}
|
||||
|
||||
if (options.sortBy) {
|
||||
qs.sort_by = options.sortBy;
|
||||
}
|
||||
if (options.sortOrder) {
|
||||
qs.sort_order = options.sortOrder;
|
||||
}
|
||||
const endpoint = (ticketType === 'regular') ? `/search` : `/suspended_tickets`;
|
||||
const property = (ticketType === 'regular') ? 'results' : 'suspended_tickets';
|
||||
if (returnAll) {
|
||||
responseData = await zendeskApiRequestAllItems.call(this, 'results', 'GET', `/search`, {}, qs);
|
||||
responseData = await zendeskApiRequestAllItems.call(this, property, 'GET', endpoint, {}, qs);
|
||||
} else {
|
||||
const limit = this.getNodeParameter('limit', i) as number;
|
||||
qs.per_page = limit;
|
||||
responseData = await zendeskApiRequest.call(this, 'GET', `/search`, {}, qs);
|
||||
responseData = responseData.results;
|
||||
responseData = await zendeskApiRequest.call(this, 'GET', endpoint, {}, qs);
|
||||
responseData = responseData.results || responseData.suspended_tickets;
|
||||
}
|
||||
}
|
||||
//https://developer.zendesk.com/rest_api/docs/support/tickets#delete-ticket
|
||||
//https://developer.zendesk.com/api-reference/ticketing/tickets/suspended_tickets/#delete-suspended-ticket
|
||||
if (operation === 'delete') {
|
||||
const ticketType = this.getNodeParameter('ticketType', i) as string;
|
||||
const ticketId = this.getNodeParameter('id', i) as string;
|
||||
const endpoint = (ticketType === 'regular') ? `/tickets/${ticketId}` : `/suspended_tickets/${ticketId}`;
|
||||
responseData = await zendeskApiRequest.call(this, 'DELETE', endpoint, {});
|
||||
responseData = { success: true };
|
||||
}
|
||||
//https://developer.zendesk.com/api-reference/ticketing/tickets/suspended_tickets/#recover-suspended-ticket
|
||||
if (operation === 'recover') {
|
||||
const ticketId = this.getNodeParameter('id', i) as string;
|
||||
try {
|
||||
responseData = await zendeskApiRequest.call(this, 'DELETE', `/tickets/${ticketId}`, {});
|
||||
responseData = await zendeskApiRequest.call(this, 'PUT', `/suspended_tickets/${ticketId}/recover`, {});
|
||||
responseData = responseData.ticket;
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user