Merge branch 'GeylaniBerk-zendesk-auth-api-token-test'

This commit is contained in:
Jan Oberhauser 2021-11-11 12:08:31 +01:00
commit 931ad58b80
2 changed files with 45 additions and 1 deletions

View file

@ -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 {

View file

@ -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 {
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