Skip to content

Commit

Permalink
feat(Intercom Node): Update credential to new style (#11485)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joffcom authored Oct 31, 2024
1 parent 130c942 commit b137e13
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
25 changes: 24 additions & 1 deletion packages/nodes-base/credentials/IntercomApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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',
},
};
}
16 changes: 4 additions & 12 deletions packages/nodes-base/nodes/Intercom/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
IHookFunctions,
ILoadOptionsFunctions,
JsonObject,
IRequestOptions,
IHttpRequestOptions,
IHttpRequestMethods,
} from 'n8n-workflow';
import { NodeApiError } from 'n8n-workflow';
Expand All @@ -18,24 +18,16 @@ export async function intercomApiRequest(
query?: IDataObject,
uri?: string,
): Promise<any> {
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);
}
Expand Down

0 comments on commit b137e13

Please sign in to comment.