From b1ba991367675d5a16ab5145260a217a5d2a6b5e Mon Sep 17 00:00:00 2001 From: Vincent Barrier Date: Sun, 8 Nov 2020 14:45:00 +0100 Subject: [PATCH] Manage custom properties on Hubspot deals --- .../nodes-base/nodes/Hubspot/Hubspot.node.ts | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/packages/nodes-base/nodes/Hubspot/Hubspot.node.ts b/packages/nodes-base/nodes/Hubspot/Hubspot.node.ts index aaae8c5895..e04a829d93 100644 --- a/packages/nodes-base/nodes/Hubspot/Hubspot.node.ts +++ b/packages/nodes-base/nodes/Hubspot/Hubspot.node.ts @@ -552,6 +552,25 @@ export class Hubspot implements INodeType { } return returnData; }, + + // Get all the deal properties to display them to user so that he can + // select them easily + async getDealCustomProperties(this: ILoadOptionsFunctions): Promise { + const returnData: INodePropertyOptions[] = []; + const endpoint = '/properties/v2/deals/properties'; + const properties = await hubspotApiRequest.call(this, 'GET', endpoint, {}); + for (const property of properties) { + if (property.hubspotDefined === null) { + const propertyName = property.label; + const propertyId = property.name; + returnData.push({ + name: propertyName, + value: propertyId, + }); + } + } + return returnData; + }, /* -------------------------------------------------------------------------- */ /* FORM */ @@ -1801,6 +1820,17 @@ export class Hubspot implements INodeType { value: additionalFields.pipeline as string, }); } + if (additionalFields.customPropertiesUi) { + const customProperties = (additionalFields.customPropertiesUi as IDataObject).customPropertiesValues as IDataObject[]; + if (customProperties) { + for (const customProperty of customProperties) { + body.properties.push({ + name: customProperty.property, + value: customProperty.value, + }); + } + } + } body.associations = association; const endpoint = '/deals/v1/deal'; responseData = await hubspotApiRequest.call(this, 'POST', endpoint, body); @@ -1846,6 +1876,17 @@ export class Hubspot implements INodeType { value: updateFields.pipeline as string, }); } + if (updateFields.customPropertiesUi) { + const customProperties = (updateFields.customPropertiesUi as IDataObject).customPropertiesValues as IDataObject[]; + if (customProperties) { + for (const customProperty of customProperties) { + body.properties.push({ + name: customProperty.property, + value: customProperty.value, + }); + } + } + } const endpoint = `/deals/v1/deal/${dealId}`; responseData = await hubspotApiRequest.call(this, 'PUT', endpoint, body); }