mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 06:34:05 -08:00
🐛 Adding credential test for Zendesk API Token
This commit is contained in:
parent
ebdd86a5f5
commit
34fea51f1e
|
@ -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<NodeCredentialTestResult> {
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue