From 34fea51f1e7826405f5a0f258c2cfa198a258fed Mon Sep 17 00:00:00 2001 From: GeylaniBerk Date: Thu, 4 Nov 2021 10:58:31 +0100 Subject: [PATCH 1/2] :bug: Adding credential test for Zendesk API Token --- .../nodes-base/nodes/Zendesk/Zendesk.node.ts | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/packages/nodes-base/nodes/Zendesk/Zendesk.node.ts b/packages/nodes-base/nodes/Zendesk/Zendesk.node.ts index 22718413d1..b6d9d173dd 100644 --- a/packages/nodes-base/nodes/Zendesk/Zendesk.node.ts +++ b/packages/nodes-base/nodes/Zendesk/Zendesk.node.ts @@ -1,8 +1,14 @@ +import { + OptionsWithUri, +} from 'request'; + import { IExecuteFunctions, } from 'n8n-core'; import { + ICredentialsDecrypted, + ICredentialTestFunctions, IDataObject, ILoadOptionsFunctions, INodeExecutionData, @@ -10,6 +16,7 @@ import { INodeType, INodeTypeDescription, NodeApiError, + NodeCredentialTestResult, NodeOperationError, } from 'n8n-workflow'; @@ -70,6 +77,7 @@ export class Zendesk implements INodeType { ], }, }, + testedBy: 'zendeskSoftwareApiTest', }, { name: 'zendeskOAuth2Api', @@ -146,6 +154,42 @@ export class Zendesk implements INodeType { }; methods = { + credentialTest: { + async zendeskSoftwareApiTest(this: ICredentialTestFunctions, credential: ICredentialsDecrypted): Promise { + const credentials = credential.data; + const subdomain = credentials!.subdomain; + const email = credentials!.email; + const apiToken = credentials!.apiToken; + + const base64Key = Buffer.from(`${email}/token:${apiToken}`).toString('base64'); + const options: OptionsWithUri = { + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Basic ${base64Key}`, + }, + method: 'GET', + uri: `https://${subdomain}.zendesk.com/api/v2/ticket_fields.json`, + qs: { + recent: 0, + }, + json: true, + timeout: 5000, + }; + + try { + const response = await this.helpers.request!(options); + } catch (error) { + return { + status: 'Error', + message: `Connection details not valid; ${error.message}`, + }; + } + return { + status: 'OK', + message: 'Authentication successful!', + }; + }, + }, loadOptions: { // Get all the custom fields to display them to user so that he can // select them easily From dc2bda4baa9d45fc9edce2862531a17f5bff9179 Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Thu, 11 Nov 2021 12:08:05 +0100 Subject: [PATCH 2/2] :zap: Minor improvements --- packages/nodes-base/nodes/Jira/Jira.node.ts | 2 +- packages/nodes-base/nodes/Zendesk/Zendesk.node.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/nodes-base/nodes/Jira/Jira.node.ts b/packages/nodes-base/nodes/Jira/Jira.node.ts index 3cd0509566..579840d3a9 100644 --- a/packages/nodes-base/nodes/Jira/Jira.node.ts +++ b/packages/nodes-base/nodes/Jira/Jira.node.ts @@ -179,7 +179,7 @@ export class Jira implements INodeType { } catch (err) { return { status: 'Error', - message: `Connection details not valid; ${err.message}`, + message: `Connection details not valid: ${err.message}`, }; } return { diff --git a/packages/nodes-base/nodes/Zendesk/Zendesk.node.ts b/packages/nodes-base/nodes/Zendesk/Zendesk.node.ts index b6d9d173dd..83c7850e74 100644 --- a/packages/nodes-base/nodes/Zendesk/Zendesk.node.ts +++ b/packages/nodes-base/nodes/Zendesk/Zendesk.node.ts @@ -177,11 +177,11 @@ export class Zendesk implements INodeType { }; try { - const response = await this.helpers.request!(options); + await this.helpers.request!(options); } catch (error) { return { status: 'Error', - message: `Connection details not valid; ${error.message}`, + message: `Connection details not valid: ${error.message}`, }; } return {