diff --git a/packages/nodes-base/nodes/Hubspot/CompanyDescription.ts b/packages/nodes-base/nodes/Hubspot/CompanyDescription.ts index b2010891d30..0eefd20ec15 100644 --- a/packages/nodes-base/nodes/Hubspot/CompanyDescription.ts +++ b/packages/nodes-base/nodes/Hubspot/CompanyDescription.ts @@ -157,6 +157,41 @@ export const companyFields = [ default: '', description: 'The country/region in which the company or organization is located.', }, + { + displayName: 'Custom Properties', + name: 'customPropertiesUi', + placeholder: 'Add Custom Property', + type: 'fixedCollection', + typeOptions: { + multipleValues: true, + }, + default: {}, + options: [ + { + name: 'customPropertiesValues', + displayName: 'Custom Property', + values: [ + { + displayName: 'Property', + name: 'property', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getCompanyCustomProperties', + }, + default: '', + description: 'Name of the property.', + }, + { + displayName: 'Value', + name: 'value', + type: 'string', + default: '', + description: 'Value of the property', + }, + ], + }, + ], + }, { displayName: 'Description', name: 'description', @@ -474,6 +509,41 @@ export const companyFields = [ default: '', description: 'The country/region in which the company or organization is located.', }, + { + displayName: 'Custom Properties', + name: 'customPropertiesUi', + placeholder: 'Add Custom Property', + type: 'fixedCollection', + typeOptions: { + multipleValues: true, + }, + default: {}, + options: [ + { + name: 'customPropertiesValues', + displayName: 'Custom Property', + values: [ + { + displayName: 'Property', + name: 'property', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getCompanyCustomProperties', + }, + default: '', + description: 'Name of the property.', + }, + { + displayName: 'Value', + name: 'value', + type: 'string', + default: '', + description: 'Value of the property', + }, + ], + }, + ], + }, { displayName: 'Description', name: 'description', diff --git a/packages/nodes-base/nodes/Hubspot/GenericFunctions.ts b/packages/nodes-base/nodes/Hubspot/GenericFunctions.ts index 2a46532bdd9..a5a05a562d2 100644 --- a/packages/nodes-base/nodes/Hubspot/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Hubspot/GenericFunctions.ts @@ -41,7 +41,6 @@ export async function hubspotApiRequest(this: IHookFunctions | IExecuteFunctions const credentials = this.getCredentials('hubspotDeveloperApi'); options.qs.hapikey = credentials!.apiKey as string; - return await this.helpers.request!(options); } else { // @ts-ignore diff --git a/packages/nodes-base/nodes/Hubspot/Hubspot.node.ts b/packages/nodes-base/nodes/Hubspot/Hubspot.node.ts index 18298614c2c..3c82f2941e6 100644 --- a/packages/nodes-base/nodes/Hubspot/Hubspot.node.ts +++ b/packages/nodes-base/nodes/Hubspot/Hubspot.node.ts @@ -526,6 +526,26 @@ export class Hubspot implements INodeType { } return returnData; }, + + // Get all the company custom properties to display them to user so that he can + // select them easily + async getCompanyCustomProperties(this: ILoadOptionsFunctions): Promise { + const returnData: INodePropertyOptions[] = []; + const endpoint = '/properties/v2/companies/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; + }, + /* -------------------------------------------------------------------------- */ /* DEAL */ /* -------------------------------------------------------------------------- */ @@ -1535,6 +1555,18 @@ export class Hubspot implements INodeType { value: additionalFields.yearFounded, }); } + if (additionalFields.customPropertiesUi) { + const customProperties = (additionalFields.customPropertiesUi as IDataObject).customPropertiesValues as IDataObject[]; + + if (customProperties) { + for (const customProperty of customProperties) { + body.push({ + name: customProperty.property, + value: customProperty.value, + }); + } + } + } const endpoint = '/companies/v2/companies'; responseData = await hubspotApiRequest.call(this, 'POST', endpoint, { properties: body }); } @@ -1747,6 +1779,18 @@ export class Hubspot implements INodeType { value: updateFields.yearFounded, }); } + if (updateFields.customPropertiesUi) { + const customProperties = (updateFields.customPropertiesUi as IDataObject).customPropertiesValues as IDataObject[]; + + if (customProperties) { + for (const customProperty of customProperties) { + body.push({ + name: customProperty.property, + value: customProperty.value, + }); + } + } + } const endpoint = `/companies/v2/companies/${companyId}`; responseData = await hubspotApiRequest.call(this, 'PUT', endpoint, { properties: body }); }