From afff86d9ae70c191624296b9f941c3a9e1ace14e Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Wed, 11 Aug 2021 13:35:21 -0400 Subject: [PATCH] :bug: Fix issue when sending context parameter to Hubspot (#2035) --- packages/nodes-base/nodes/Hubspot/GenericFunctions.ts | 11 +++++++++++ packages/nodes-base/nodes/Hubspot/Hubspot.node.ts | 2 ++ 2 files changed, 13 insertions(+) diff --git a/packages/nodes-base/nodes/Hubspot/GenericFunctions.ts b/packages/nodes-base/nodes/Hubspot/GenericFunctions.ts index 352e2da88b..b8fec59383 100644 --- a/packages/nodes-base/nodes/Hubspot/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Hubspot/GenericFunctions.ts @@ -91,6 +91,17 @@ export function validateJSON(json: string | undefined): any { // tslint:disable- return result; } + +// tslint:disable-next-line: no-any +export function clean(obj: any) { + for (const propName in obj) { + if (obj[propName] === null || obj[propName] === undefined || obj[propName] === '') { + delete obj[propName]; + } + } + return obj; +} + export const propertyEvents = [ 'contact.propertyChange', 'company.propertyChange', diff --git a/packages/nodes-base/nodes/Hubspot/Hubspot.node.ts b/packages/nodes-base/nodes/Hubspot/Hubspot.node.ts index c6659f53e0..213619af44 100644 --- a/packages/nodes-base/nodes/Hubspot/Hubspot.node.ts +++ b/packages/nodes-base/nodes/Hubspot/Hubspot.node.ts @@ -12,6 +12,7 @@ import { } from 'n8n-workflow'; import { + clean, hubspotApiRequest, hubspotApiRequestAllItems, } from './GenericFunctions'; @@ -2169,6 +2170,7 @@ export class Hubspot implements INodeType { Object.assign(body, { legalConsentOptions: { legitimateInterest: legitimateInteres } }); } if (context) { + clean(context); Object.assign(body, { context }); } const uri = `https://api.hsforms.com/submissions/v3/integration/submit/${portalId}/${formId}`;