From 0a3a572a602d5be5631eea9231fc8d348a88ff86 Mon Sep 17 00:00:00 2001 From: Rene Wagner Date: Thu, 13 Oct 2022 09:03:44 +0200 Subject: [PATCH] (mod) added test requests and simplified authenticationMethod selection --- .../nodes-base/credentials/HubspotApi.credentials.ts | 9 ++++++++- .../credentials/HubspotAppToken.credentials.ts | 9 ++++++++- packages/nodes-base/nodes/Hubspot/GenericFunctions.ts | 6 ++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/nodes-base/credentials/HubspotApi.credentials.ts b/packages/nodes-base/credentials/HubspotApi.credentials.ts index 1a1906692f43e7..bda8e42b97f243 100644 --- a/packages/nodes-base/credentials/HubspotApi.credentials.ts +++ b/packages/nodes-base/credentials/HubspotApi.credentials.ts @@ -1,4 +1,4 @@ -import { IAuthenticateGeneric, ICredentialType, INodeProperties } from 'n8n-workflow'; +import { IAuthenticateGeneric, ICredentialTestRequest, ICredentialType, INodeProperties } from 'n8n-workflow'; export class HubspotApi implements ICredentialType { name = 'hubspotApi'; @@ -21,4 +21,11 @@ export class HubspotApi implements ICredentialType { }, }, }; + + 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 9e95f83034debd..0bd7ffda436c69 100644 --- a/packages/nodes-base/credentials/HubspotAppToken.credentials.ts +++ b/packages/nodes-base/credentials/HubspotAppToken.credentials.ts @@ -1,4 +1,4 @@ -import { IAuthenticateGeneric, ICredentialType, INodeProperties } from 'n8n-workflow'; +import { IAuthenticateGeneric, ICredentialTestRequest, ICredentialType, INodeProperties } from 'n8n-workflow'; export class HubspotAppToken implements ICredentialType { name = 'hubspotAppToken'; @@ -21,4 +21,11 @@ export class HubspotAppToken implements ICredentialType { }, }, }; + + 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 eda2a56575b189..acc2b3cd3a9acf 100644 --- a/packages/nodes-base/nodes/Hubspot/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Hubspot/GenericFunctions.ts @@ -38,10 +38,8 @@ export async function hubspotApiRequest(this: IHookFunctions | IExecuteFunctions }; try { - if (authenticationMethod === 'apiKey') { - return this.helpers.requestWithAuthentication.call(this, 'hubspotApi', options); - } else if (authenticationMethod === 'appToken') { - return this.helpers.requestWithAuthentication.call(this, 'hubspotAppToken', options); + if (authenticationMethod === 'apiKey' || authenticationMethod === 'appToken') { + return this.helpers.requestWithAuthentication.call(this, authenticationMethod, options); } else if (authenticationMethod === 'developerApi') { if (endpoint.includes('webhooks')) {