From b137e13845f0714ebf7421c837f5ab104b66709b Mon Sep 17 00:00:00 2001 From: Jon Date: Thu, 31 Oct 2024 16:38:11 +0000 Subject: [PATCH] feat(Intercom Node): Update credential to new style (#11485) --- .../credentials/IntercomApi.credentials.ts | 25 ++++++++++++++++++- .../nodes/Intercom/GenericFunctions.ts | 16 +++--------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/packages/nodes-base/credentials/IntercomApi.credentials.ts b/packages/nodes-base/credentials/IntercomApi.credentials.ts index 4145121d4f..b4b129ab5c 100644 --- a/packages/nodes-base/credentials/IntercomApi.credentials.ts +++ b/packages/nodes-base/credentials/IntercomApi.credentials.ts @@ -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 { name = 'intercomApi'; @@ -16,4 +21,22 @@ export class IntercomApi implements ICredentialType { 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', + }, + }; } diff --git a/packages/nodes-base/nodes/Intercom/GenericFunctions.ts b/packages/nodes-base/nodes/Intercom/GenericFunctions.ts index 6ebbfd0642..33bad3f4de 100644 --- a/packages/nodes-base/nodes/Intercom/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Intercom/GenericFunctions.ts @@ -4,7 +4,7 @@ import type { IHookFunctions, ILoadOptionsFunctions, JsonObject, - IRequestOptions, + IHttpRequestOptions, IHttpRequestMethods, } from 'n8n-workflow'; import { NodeApiError } from 'n8n-workflow'; @@ -18,24 +18,16 @@ export async function intercomApiRequest( query?: IDataObject, uri?: string, ): Promise { - const credentials = await this.getCredentials('intercomApi'); - - const headerWithAuthentication = Object.assign( - {}, - { Authorization: `Bearer ${credentials.apiKey}`, Accept: 'application/json' }, - ); - - const options: IRequestOptions = { - headers: headerWithAuthentication, + const options: IHttpRequestOptions = { method, qs: query, - uri: uri || `https://api.intercom.io${endpoint}`, + url: uri ?? `https://api.intercom.io${endpoint}`, body, json: true, }; try { - return await this.helpers.request(options); + return await this.helpers.httpRequestWithAuthentication.call(this, 'intercomApi', options); } catch (error) { throw new NodeApiError(this.getNode(), error as JsonObject); }