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