mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
feat(Intercom Node): Update credential to new style (#11485)
This commit is contained in:
@@ -1,4 +1,9 @@
|
|||||||
import type { ICredentialType, INodeProperties } from 'n8n-workflow';
|
import type {
|
||||||
|
IAuthenticateGeneric,
|
||||||
|
ICredentialTestRequest,
|
||||||
|
ICredentialType,
|
||||||
|
INodeProperties,
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
export class IntercomApi implements ICredentialType {
|
export class IntercomApi implements ICredentialType {
|
||||||
name = 'intercomApi';
|
name = 'intercomApi';
|
||||||
@@ -16,4 +21,22 @@ export class IntercomApi implements ICredentialType {
|
|||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
authenticate: IAuthenticateGeneric = {
|
||||||
|
type: 'generic',
|
||||||
|
properties: {
|
||||||
|
headers: {
|
||||||
|
Authorization: '=Bearer {{$credentials.apiKey}}',
|
||||||
|
Accept: 'application/json',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
test: ICredentialTestRequest = {
|
||||||
|
request: {
|
||||||
|
baseURL: 'https://api.intercom.io',
|
||||||
|
url: '/me',
|
||||||
|
method: 'GET',
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import type {
|
|||||||
IHookFunctions,
|
IHookFunctions,
|
||||||
ILoadOptionsFunctions,
|
ILoadOptionsFunctions,
|
||||||
JsonObject,
|
JsonObject,
|
||||||
IRequestOptions,
|
IHttpRequestOptions,
|
||||||
IHttpRequestMethods,
|
IHttpRequestMethods,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
import { NodeApiError } from 'n8n-workflow';
|
import { NodeApiError } from 'n8n-workflow';
|
||||||
@@ -18,24 +18,16 @@ export async function intercomApiRequest(
|
|||||||
query?: IDataObject,
|
query?: IDataObject,
|
||||||
uri?: string,
|
uri?: string,
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const credentials = await this.getCredentials('intercomApi');
|
const options: IHttpRequestOptions = {
|
||||||
|
|
||||||
const headerWithAuthentication = Object.assign(
|
|
||||||
{},
|
|
||||||
{ Authorization: `Bearer ${credentials.apiKey}`, Accept: 'application/json' },
|
|
||||||
);
|
|
||||||
|
|
||||||
const options: IRequestOptions = {
|
|
||||||
headers: headerWithAuthentication,
|
|
||||||
method,
|
method,
|
||||||
qs: query,
|
qs: query,
|
||||||
uri: uri || `https://api.intercom.io${endpoint}`,
|
url: uri ?? `https://api.intercom.io${endpoint}`,
|
||||||
body,
|
body,
|
||||||
json: true,
|
json: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return await this.helpers.request(options);
|
return await this.helpers.httpRequestWithAuthentication.call(this, 'intercomApi', options);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new NodeApiError(this.getNode(), error as JsonObject);
|
throw new NodeApiError(this.getNode(), error as JsonObject);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user