2023-01-27 03:22:44 -08:00
|
|
|
import type {
|
2022-04-18 09:43:09 -07:00
|
|
|
ICredentialDataDecryptedObject,
|
|
|
|
ICredentialTestRequest,
|
2020-01-05 10:34:09 -08:00
|
|
|
ICredentialType,
|
2022-04-18 09:43:09 -07:00
|
|
|
IHttpRequestOptions,
|
2021-06-12 09:39:55 -07:00
|
|
|
INodeProperties,
|
2020-01-05 10:34:09 -08:00
|
|
|
} from 'n8n-workflow';
|
|
|
|
|
|
|
|
export class ZendeskApi implements ICredentialType {
|
|
|
|
name = 'zendeskApi';
|
2022-12-02 12:54:28 -08:00
|
|
|
|
2020-01-05 10:34:09 -08:00
|
|
|
displayName = 'Zendesk API';
|
2022-12-02 12:54:28 -08:00
|
|
|
|
2020-08-17 05:42:09 -07:00
|
|
|
documentationUrl = 'zendesk';
|
2022-12-02 12:54:28 -08:00
|
|
|
|
2021-06-12 09:39:55 -07:00
|
|
|
properties: INodeProperties[] = [
|
2020-01-05 10:34:09 -08:00
|
|
|
{
|
2020-06-09 05:00:41 -07:00
|
|
|
displayName: 'Subdomain',
|
|
|
|
name: 'subdomain',
|
2021-06-12 09:39:55 -07:00
|
|
|
type: 'string',
|
2022-04-13 23:32:27 -07:00
|
|
|
description: 'The subdomain of your Zendesk work environment',
|
2020-08-27 00:00:01 -07:00
|
|
|
placeholder: 'company',
|
|
|
|
default: '',
|
2020-01-05 10:34:09 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Email',
|
|
|
|
name: 'email',
|
2021-06-12 09:39:55 -07:00
|
|
|
type: 'string',
|
2022-06-20 07:54:01 -07:00
|
|
|
placeholder: 'name@email.com',
|
2020-01-05 10:34:09 -08:00
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'API Token',
|
|
|
|
name: 'apiToken',
|
2021-06-12 09:39:55 -07:00
|
|
|
type: 'string',
|
2020-01-05 10:34:09 -08:00
|
|
|
default: '',
|
2023-06-21 08:19:29 -07:00
|
|
|
typeOptions: {
|
|
|
|
password: true,
|
|
|
|
},
|
2020-01-05 10:34:09 -08:00
|
|
|
},
|
|
|
|
];
|
2022-12-02 12:54:28 -08:00
|
|
|
|
2022-07-24 08:36:17 -07:00
|
|
|
async authenticate(
|
|
|
|
credentials: ICredentialDataDecryptedObject,
|
|
|
|
requestOptions: IHttpRequestOptions,
|
|
|
|
): Promise<IHttpRequestOptions> {
|
2022-04-18 09:43:09 -07:00
|
|
|
requestOptions.auth = {
|
|
|
|
username: `${credentials.email}/token`,
|
|
|
|
password: credentials.apiToken as string,
|
|
|
|
};
|
|
|
|
return requestOptions;
|
2022-04-18 10:31:59 -07:00
|
|
|
}
|
2022-12-02 12:54:28 -08:00
|
|
|
|
2022-04-18 09:43:09 -07:00
|
|
|
test: ICredentialTestRequest = {
|
|
|
|
request: {
|
|
|
|
baseURL: '=https://{{$credentials.subdomain}}.zendesk.com/api/v2',
|
|
|
|
url: '/ticket_fields.json',
|
|
|
|
},
|
|
|
|
};
|
2020-01-05 10:34:09 -08:00
|
|
|
}
|