mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
✨ Add Organization resource to Zendesk node (#2152)
* Added Organization options. Create, Update, Get, GetAll, Delete, Count and Related * Fixed Zendesk Node user alias typo * Updated Zendesk documentation links for future maintainers * Added Related for Users in Zendesk Node * Added fetching organizations for users * 🔨 Refactor Zendesk expansion * ⚡ Improvements Co-authored-by: Jonathan <jonathan.bennetts@gmail.com> Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
This commit is contained in:
@@ -34,6 +34,11 @@ import {
|
||||
userOperations
|
||||
} from './UserDescription';
|
||||
|
||||
import {
|
||||
organizationFields,
|
||||
organizationOperations
|
||||
} from './OrganizationDescription';
|
||||
|
||||
import {
|
||||
IComment,
|
||||
ITicket,
|
||||
@@ -43,7 +48,7 @@ export class Zendesk implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Zendesk',
|
||||
name: 'zendesk',
|
||||
icon: 'file:zendesk.png',
|
||||
icon: 'file:zendesk.svg',
|
||||
group: ['output'],
|
||||
version: 1,
|
||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||
@@ -116,6 +121,11 @@ export class Zendesk implements INodeType {
|
||||
value: 'user',
|
||||
description: 'Manage users',
|
||||
},
|
||||
{
|
||||
name: 'Organization',
|
||||
value: 'organization',
|
||||
description: 'Manage organizations',
|
||||
},
|
||||
],
|
||||
default: 'ticket',
|
||||
description: 'Resource to consume.',
|
||||
@@ -129,6 +139,9 @@ export class Zendesk implements INodeType {
|
||||
// USER
|
||||
...userOperations,
|
||||
...userFields,
|
||||
// ORGANIZATION
|
||||
...organizationOperations,
|
||||
...organizationFields,
|
||||
],
|
||||
};
|
||||
|
||||
@@ -223,6 +236,33 @@ export class Zendesk implements INodeType {
|
||||
}
|
||||
return returnData;
|
||||
},
|
||||
|
||||
// Get all the organization fields to display them to the user for easy selection
|
||||
async getOrganizationFields(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
const fields = await zendeskApiRequestAllItems.call(this, 'organization_fields', 'GET', '/organization_fields');
|
||||
for (const field of fields) {
|
||||
const fieldName = field.title;
|
||||
const fieldId = field.key;
|
||||
returnData.push({
|
||||
name: fieldName,
|
||||
value: fieldId,
|
||||
});
|
||||
}
|
||||
return returnData;
|
||||
},
|
||||
|
||||
async getOrganizations(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
const fields = await zendeskApiRequestAllItems.call(this, 'organizations', 'GET', `/organizations`, {}, {});
|
||||
for (const field of fields) {
|
||||
returnData.push({
|
||||
name: field.name,
|
||||
value: field.id,
|
||||
});
|
||||
}
|
||||
return returnData;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -236,7 +276,7 @@ export class Zendesk implements INodeType {
|
||||
try {
|
||||
const resource = this.getNodeParameter('resource', 0) as string;
|
||||
const operation = this.getNodeParameter('operation', 0) as string;
|
||||
//https://developer.zendesk.com/rest_api/docs/support/introduction
|
||||
//https://developer.zendesk.com/api-reference/ticketing/introduction/
|
||||
if (resource === 'ticket') {
|
||||
//https://developer.zendesk.com/rest_api/docs/support/tickets
|
||||
if (operation === 'create') {
|
||||
@@ -385,7 +425,7 @@ export class Zendesk implements INodeType {
|
||||
}
|
||||
}
|
||||
}
|
||||
//https://developer.zendesk.com/rest_api/docs/support/ticket_fields
|
||||
//https://developer.zendesk.com/api-reference/ticketing/tickets/ticket_fields/
|
||||
if (resource === 'ticketField') {
|
||||
//https://developer.zendesk.com/rest_api/docs/support/tickets#show-ticket
|
||||
if (operation === 'get') {
|
||||
@@ -406,9 +446,9 @@ export class Zendesk implements INodeType {
|
||||
}
|
||||
}
|
||||
}
|
||||
//https://developer.zendesk.com/rest_api/docs/support/users
|
||||
//https://developer.zendesk.com/api-reference/ticketing/users/users/
|
||||
if (resource === 'user') {
|
||||
//https://developer.zendesk.com/rest_api/docs/support/users#create-user
|
||||
//https://developer.zendesk.com/api-reference/ticketing/users/users/#create-user
|
||||
if (operation === 'create') {
|
||||
const name = this.getNodeParameter('name', i) as string;
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||
@@ -430,11 +470,10 @@ export class Zendesk implements INodeType {
|
||||
delete body.userFieldsUi;
|
||||
}
|
||||
}
|
||||
|
||||
responseData = await zendeskApiRequest.call(this, 'POST', '/users', { user: body });
|
||||
responseData = responseData.user;
|
||||
}
|
||||
//https://developer.zendesk.com/rest_api/docs/support/tickets#update-ticket
|
||||
//https://developer.zendesk.com/api-reference/ticketing/users/users/#update-user
|
||||
if (operation === 'update') {
|
||||
const userId = this.getNodeParameter('id', i) as string;
|
||||
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
||||
@@ -458,13 +497,13 @@ export class Zendesk implements INodeType {
|
||||
responseData = await zendeskApiRequest.call(this, 'PUT', `/users/${userId}`, { user: body });
|
||||
responseData = responseData.user;
|
||||
}
|
||||
//https://developer.zendesk.com/rest_api/docs/support/users#show-user
|
||||
//https://developer.zendesk.com/api-reference/ticketing/users/users/#show-user
|
||||
if (operation === 'get') {
|
||||
const userId = this.getNodeParameter('id', i) as string;
|
||||
responseData = await zendeskApiRequest.call(this, 'GET', `/users/${userId}`, {});
|
||||
responseData = responseData.user;
|
||||
}
|
||||
//https://developer.zendesk.com/rest_api/docs/support/users#list-users
|
||||
//https://developer.zendesk.com/api-reference/ticketing/users/users/#list-users
|
||||
if (operation === 'getAll') {
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
const options = this.getNodeParameter('filters', i) as IDataObject;
|
||||
@@ -480,7 +519,13 @@ export class Zendesk implements INodeType {
|
||||
responseData = responseData.users;
|
||||
}
|
||||
}
|
||||
//https://developer.zendesk.com/rest_api/docs/support/users#search-users
|
||||
//https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#list-organizations
|
||||
if (operation === 'getOrganizations') {
|
||||
const userId = this.getNodeParameter('id', i) as string;
|
||||
responseData = await zendeskApiRequest.call(this, 'GET', `/users/${userId}/organizations`, {});
|
||||
responseData = responseData.organizations;
|
||||
}
|
||||
//https://developer.zendesk.com/api-reference/ticketing/users/users/#search-users
|
||||
if (operation === 'search') {
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
const options = this.getNodeParameter('filters', i) as IDataObject;
|
||||
@@ -496,12 +541,106 @@ export class Zendesk implements INodeType {
|
||||
responseData = responseData.users;
|
||||
}
|
||||
}
|
||||
//https://developer.zendesk.com/rest_api/docs/support/users#delete-user
|
||||
//https://developer.zendesk.com/api-reference/ticketing/users/users/#delete-user
|
||||
if (operation === 'delete') {
|
||||
const userId = this.getNodeParameter('id', i) as string;
|
||||
responseData = await zendeskApiRequest.call(this, 'DELETE', `/users/${userId}`, {});
|
||||
responseData = responseData.user;
|
||||
}
|
||||
//https://developer.zendesk.com/api-reference/ticketing/users/users/#show-user-related-information
|
||||
if (operation === 'getRelatedData') {
|
||||
const userId = this.getNodeParameter('id', i) as string;
|
||||
responseData = await zendeskApiRequest.call(this, 'GET', `/users/${userId}/related`, {});
|
||||
responseData = responseData.user_related;
|
||||
}
|
||||
}
|
||||
//https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/
|
||||
if (resource === 'organization') {
|
||||
//https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#create-organization
|
||||
if (operation === 'create') {
|
||||
const name = this.getNodeParameter('name', i) as string;
|
||||
|
||||
const body: IDataObject & { name: string; organization_fields?: { [key: string]: object | string } } = {
|
||||
name,
|
||||
};
|
||||
|
||||
const { organizationFieldsUi, ...rest } = this.getNodeParameter('additionalFields', i) as IDataObject & { organizationFieldsUi?: { organizationFieldValues: Array<{ field: string; value: string; }> } };
|
||||
|
||||
Object.assign(body, rest);
|
||||
|
||||
if (organizationFieldsUi?.organizationFieldValues.length) {
|
||||
const organizationFields = organizationFieldsUi.organizationFieldValues;
|
||||
if (organizationFields.length) {
|
||||
body.organization_fields = {};
|
||||
for (const organizationField of organizationFields) {
|
||||
body.organization_fields[organizationField.field] = organizationField.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
responseData = await zendeskApiRequest.call(this, 'POST', '/organizations', { organization: body });
|
||||
responseData = responseData.organization;
|
||||
}
|
||||
//https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#delete-organization
|
||||
if (operation === 'delete') {
|
||||
const organizationId = this.getNodeParameter('id', i) as string;
|
||||
await zendeskApiRequest.call(this, 'DELETE', `/organizations/${organizationId}`, {});
|
||||
responseData = { success: true };
|
||||
}
|
||||
//https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#count-organizations
|
||||
if (operation === 'count') {
|
||||
responseData = await zendeskApiRequest.call(this, 'GET', `/organizations/count`, {});
|
||||
responseData = responseData.count;
|
||||
}
|
||||
//https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-organization
|
||||
if (operation === 'get') {
|
||||
const organizationId = this.getNodeParameter('id', i) as string;
|
||||
responseData = await zendeskApiRequest.call(this, 'GET', `/organizations/${organizationId}`, {});
|
||||
responseData = responseData.organization;
|
||||
}
|
||||
//https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#list-organizations
|
||||
if (operation === 'getAll') {
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
|
||||
if (returnAll) {
|
||||
responseData = await zendeskApiRequestAllItems.call(this, 'organizations', 'GET', `/organizations`, {}, qs);
|
||||
} else {
|
||||
const limit = this.getNodeParameter('limit', i) as number;
|
||||
qs.per_page = limit;
|
||||
responseData = await zendeskApiRequest.call(this, 'GET', `/organizations`, {}, qs);
|
||||
responseData = responseData.organizations;
|
||||
}
|
||||
}
|
||||
//https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-organizations-related-information
|
||||
if (operation === 'getRelatedData') {
|
||||
const organizationId = this.getNodeParameter('id', i) as string;
|
||||
responseData = await zendeskApiRequest.call(this, 'GET', `/organizations/${organizationId}/related`, {});
|
||||
responseData = responseData.organization_related;
|
||||
}
|
||||
//https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#update-organization
|
||||
if (operation === 'update') {
|
||||
const organizationId = this.getNodeParameter('id', i) as string;
|
||||
|
||||
const body: IDataObject & { organization_fields?: { [key: string]: object | string } } = {};
|
||||
|
||||
const { organizationFieldsUi, ...rest } = this.getNodeParameter('updateFields', i) as IDataObject & { organizationFieldsUi?: { organizationFieldValues: Array<{ field: string; value: string; }> } };
|
||||
|
||||
Object.assign(body, rest);
|
||||
|
||||
if (organizationFieldsUi?.organizationFieldValues.length) {
|
||||
const organizationFields = organizationFieldsUi.organizationFieldValues;
|
||||
if (organizationFields.length) {
|
||||
body.organization_fields = {};
|
||||
for (const organizationField of organizationFields) {
|
||||
body.organization_fields[organizationField.field] = organizationField.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
responseData = await zendeskApiRequest.call(this, 'PUT', `/organizations/${organizationId}`, { organization: body });
|
||||
responseData = responseData.organization;
|
||||
}
|
||||
|
||||
}
|
||||
if (Array.isArray(responseData)) {
|
||||
returnData.push.apply(returnData, responseData as IDataObject[]);
|
||||
|
||||
Reference in New Issue
Block a user