diff --git a/packages/nodes-base/credentials/HubspotApi.credentials.ts b/packages/nodes-base/credentials/HubspotApi.credentials.ts index 76fbb504525ee..bda8e42b97f24 100644 --- a/packages/nodes-base/credentials/HubspotApi.credentials.ts +++ b/packages/nodes-base/credentials/HubspotApi.credentials.ts @@ -1,4 +1,4 @@ -import { ICredentialType, INodeProperties } from 'n8n-workflow'; +import { IAuthenticateGeneric, ICredentialTestRequest, ICredentialType, INodeProperties } from 'n8n-workflow'; export class HubspotApi implements ICredentialType { name = 'hubspotApi'; @@ -12,4 +12,20 @@ export class HubspotApi implements ICredentialType { default: '', }, ]; + + authenticate: IAuthenticateGeneric = { + type: 'generic', + properties: { + qs: { + hapikey: '={{$credentials.apiKey}}', + }, + }, + }; + + test: ICredentialTestRequest = { + request: { + baseURL: 'https://api.hubapi.com', + url: '/account-info/v3/details', + }, + }; } diff --git a/packages/nodes-base/credentials/HubspotAppToken.credentials.ts b/packages/nodes-base/credentials/HubspotAppToken.credentials.ts index ee6681705c304..0bd7ffda436c6 100644 --- a/packages/nodes-base/credentials/HubspotAppToken.credentials.ts +++ b/packages/nodes-base/credentials/HubspotAppToken.credentials.ts @@ -1,4 +1,4 @@ -import { ICredentialType, INodeProperties } from 'n8n-workflow'; +import { IAuthenticateGeneric, ICredentialTestRequest, ICredentialType, INodeProperties } from 'n8n-workflow'; export class HubspotAppToken implements ICredentialType { name = 'hubspotAppToken'; @@ -12,4 +12,20 @@ export class HubspotAppToken implements ICredentialType { default: '', }, ]; + + authenticate: IAuthenticateGeneric = { + type: 'generic', + properties: { + headers: { + Authorization: '=Bearer {{$credentials.appToken}}', + }, + }, + }; + + test: ICredentialTestRequest = { + request: { + baseURL: 'https://api.hubapi.com', + url: '/account-info/v3/details', + }, + }; } diff --git a/packages/nodes-base/nodes/Hubspot/GenericFunctions.ts b/packages/nodes-base/nodes/Hubspot/GenericFunctions.ts index fdade2001be29..5d5303879b8a4 100644 --- a/packages/nodes-base/nodes/Hubspot/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Hubspot/GenericFunctions.ts @@ -38,16 +38,9 @@ export async function hubspotApiRequest(this: IHookFunctions | IExecuteFunctions }; try { - if (authenticationMethod === 'apiKey') { - const credentials = await this.getCredentials('hubspotApi'); - - options.qs.hapikey = credentials.apiKey as string; - return await this.helpers.request!(options); - } else if (authenticationMethod === 'appToken') { - const credentials = await this.getCredentials('hubspotAppToken'); - - options.headers!['Authorization'] = `Bearer ${credentials.appToken}`; - return await this.helpers.request!(options); + if (authenticationMethod === 'apiKey' || authenticationMethod === 'appToken') { + const credentialType = authenticationMethod === 'apiKey' ? 'hubspotApi' : 'hubspotAppToken'; + return this.helpers.requestWithAuthentication.call(this, credentialType, options); } else if (authenticationMethod === 'developerApi') { if (endpoint.includes('webhooks')) {