🐛 Fix issue when sending context parameter to Hubspot (#2035)

This commit is contained in:
Ricardo Espinoza 2021-08-11 13:35:21 -04:00 committed by GitHub
parent 47fbd5e762
commit afff86d9ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View file

@ -91,6 +91,17 @@ export function validateJSON(json: string | undefined): any { // tslint:disable-
return result; 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 = [ export const propertyEvents = [
'contact.propertyChange', 'contact.propertyChange',
'company.propertyChange', 'company.propertyChange',

View file

@ -12,6 +12,7 @@ import {
} from 'n8n-workflow'; } from 'n8n-workflow';
import { import {
clean,
hubspotApiRequest, hubspotApiRequest,
hubspotApiRequestAllItems, hubspotApiRequestAllItems,
} from './GenericFunctions'; } from './GenericFunctions';
@ -2169,6 +2170,7 @@ export class Hubspot implements INodeType {
Object.assign(body, { legalConsentOptions: { legitimateInterest: legitimateInteres } }); Object.assign(body, { legalConsentOptions: { legitimateInterest: legitimateInteres } });
} }
if (context) { if (context) {
clean(context);
Object.assign(body, { context }); Object.assign(body, { context });
} }
const uri = `https://api.hsforms.com/submissions/v3/integration/submit/${portalId}/${formId}`; const uri = `https://api.hsforms.com/submissions/v3/integration/submit/${portalId}/${formId}`;