diff --git a/packages/nodes-base/nodes/Hubspot/GenericFunctions.ts b/packages/nodes-base/nodes/Hubspot/GenericFunctions.ts index 41fda1f711..427446ac6d 100644 --- a/packages/nodes-base/nodes/Hubspot/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Hubspot/GenericFunctions.ts @@ -12,12 +12,11 @@ import { } from 'n8n-workflow'; export async function hubspotApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, endpoint: string, body: any = {}, query: IDataObject = {}, uri?: string): Promise { // tslint:disable-line:no-any - let credentials; - try { - credentials = this.getCredentials('hubspotApi'); - } catch (exception) { - credentials = this.getCredentials('hubspotDeveloperApi'); - } + + const node = this.getNode(); + const credentialName = Object.keys(node.credentials!)[0]; + const credentials = this.getCredentials(credentialName); + query!.hapikey = credentials!.apiKey as string; const options: OptionsWithUri = { method, @@ -31,13 +30,8 @@ export async function hubspotApiRequest(this: IHookFunctions | IExecuteFunctions try { return await this.helpers.request!(options); } catch (error) { - console.log(error) - const errorMessage = error.response.body.message || error.response.body.Message; - - if (errorMessage !== undefined) { - throw errorMessage; - } - throw error.response.body; + const errorMessage = error.response.body.message || error.response.body.Message || error.message; + throw new Error(`Hubspot error response [${error.statusCode}]: ${errorMessage}`); } } diff --git a/packages/nodes-base/nodes/Hubspot/HubspotTrigger.node.ts b/packages/nodes-base/nodes/Hubspot/HubspotTrigger.node.ts index d6cee29403..c1409765ac 100644 --- a/packages/nodes-base/nodes/Hubspot/HubspotTrigger.node.ts +++ b/packages/nodes-base/nodes/Hubspot/HubspotTrigger.node.ts @@ -191,7 +191,7 @@ export class HubspotTrigger implements INodeType { 'deal.propertyChange', ]; let endpoint = `/webhooks/v1/${app}/settings`; - let body = { + let body: IDataObject = { webhookUrl, maxConcurrentRequests: additionalFields.maxConcurrentRequests || 5, }; @@ -199,7 +199,6 @@ export class HubspotTrigger implements INodeType { endpoint = `/webhooks/v1/${app}/subscriptions`; body = { - //@ts-ignore subscriptionDetails: { subscriptionType: event, }, @@ -246,11 +245,11 @@ export class HubspotTrigger implements INodeType { async webhook(this: IWebhookFunctions): Promise { const credentials = this.getCredentials('hubspotDeveloperApi'); - const req = this.getRequestObject() + const req = this.getRequestObject(); const bodyData = req.body; const headerData = this.getHeaderData(); //@ts-ignore - if (headerData['x-hubspot-signature'] == undefined) { + if (headerData['x-hubspot-signature'] === undefined) { return {}; } const hash = `${credentials!.clientSecret}${JSON.stringify(bodyData)}`;