mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 04:04:06 -08:00
🔀 Merge branch 'zendesk-auth-api-token-test' of https://github.com/GeylaniBerk/n8n into GeylaniBerk-zendesk-auth-api-token-test
This commit is contained in:
commit
18f0ad636c
|
@ -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