mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 20:24: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 {
|
import {
|
||||||
IExecuteFunctions,
|
IExecuteFunctions,
|
||||||
} from 'n8n-core';
|
} from 'n8n-core';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
ICredentialsDecrypted,
|
||||||
|
ICredentialTestFunctions,
|
||||||
IDataObject,
|
IDataObject,
|
||||||
ILoadOptionsFunctions,
|
ILoadOptionsFunctions,
|
||||||
INodeExecutionData,
|
INodeExecutionData,
|
||||||
|
@ -10,6 +16,7 @@ import {
|
||||||
INodeType,
|
INodeType,
|
||||||
INodeTypeDescription,
|
INodeTypeDescription,
|
||||||
NodeApiError,
|
NodeApiError,
|
||||||
|
NodeCredentialTestResult,
|
||||||
NodeOperationError,
|
NodeOperationError,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
@ -70,6 +77,7 @@ export class Zendesk implements INodeType {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
testedBy: 'zendeskSoftwareApiTest',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'zendeskOAuth2Api',
|
name: 'zendeskOAuth2Api',
|
||||||
|
@ -146,6 +154,42 @@ export class Zendesk implements INodeType {
|
||||||
};
|
};
|
||||||
|
|
||||||
methods = {
|
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: {
|
loadOptions: {
|
||||||
// Get all the custom fields to display them to user so that he can
|
// Get all the custom fields to display them to user so that he can
|
||||||
// select them easily
|
// select them easily
|
||||||
|
|
Loading…
Reference in a new issue