diff --git a/packages/nodes-base/nodes/Hubspot/Hubspot.node.ts b/packages/nodes-base/nodes/Hubspot/Hubspot.node.ts index c78488e73b..f20a3c7746 100644 --- a/packages/nodes-base/nodes/Hubspot/Hubspot.node.ts +++ b/packages/nodes-base/nodes/Hubspot/Hubspot.node.ts @@ -14,12 +14,13 @@ export class Hubspot extends VersionedNodeType { group: ['output'], subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}', description: 'Consume HubSpot API', - defaultVersion: 2, + defaultVersion: 2.1, }; const nodeVersions: IVersionedNodeType['nodeVersions'] = { 1: new HubspotV1(baseDescription), 2: new HubspotV2(baseDescription), + 2.1: new HubspotV2(baseDescription), }; super(nodeVersions, baseDescription); diff --git a/packages/nodes-base/nodes/Hubspot/V2/DealDescription.ts b/packages/nodes-base/nodes/Hubspot/V2/DealDescription.ts index 638090418a..ad28d00d0e 100644 --- a/packages/nodes-base/nodes/Hubspot/V2/DealDescription.ts +++ b/packages/nodes-base/nodes/Hubspot/V2/DealDescription.ts @@ -588,6 +588,40 @@ export const dealFields: INodeProperties[] = [ description: 'Whether to include the IDs of the associated contacts and companies in the results. This will also automatically include the num_associated_contacts property.', }, + { + displayName: 'Deal Properties to Include', + name: 'properties', + type: 'multiOptions', + typeOptions: { + loadOptionsMethod: 'getDealProperties', + }, + default: [], + // eslint-disable-next-line n8n-nodes-base/node-param-description-wrong-for-dynamic-multi-options + description: + 'Include specific deal properties in the results. By default, the results will only include Deal ID and will not include the values for any properties for your Deals.', + displayOptions: { + show: { + '@version': [{ _cnd: { gt: 2 } }], + }, + }, + }, + { + displayName: 'Deal Properties with History to Include', + name: 'propertiesWithHistory', + type: 'multiOptions', + typeOptions: { + loadOptionsMethod: 'getDealProperties', + }, + default: [], + // eslint-disable-next-line n8n-nodes-base/node-param-description-wrong-for-dynamic-multi-options + description: + 'Works similarly to properties, but this parameter will include the history for the specified property', + displayOptions: { + show: { + '@version': [{ _cnd: { gt: 2 } }], + }, + }, + }, { displayName: 'Deal Properties to Include', name: 'propertiesCollection', @@ -603,7 +637,7 @@ export const dealFields: INodeProperties[] = [ name: 'properties', type: 'multiOptions', typeOptions: { - loadOptionsMethod: 'getDealPropertiesWithType', + loadOptionsMethod: 'getDealProperties', }, default: [], description: @@ -632,6 +666,11 @@ export const dealFields: INodeProperties[] = [ ], description: '

Used to include specific deal properties in the results. By default, the results will only include Deal ID and will not include the values for any properties for your Deals.

Including this parameter will include the data for the specified property in the results. You can include this parameter multiple times to request multiple properties separated by a comma: ,.

. Choose from the list, or specify IDs using an expression.', + displayOptions: { + show: { + '@version': [2], + }, + }, }, ], }, diff --git a/packages/nodes-base/nodes/Hubspot/V2/HubspotV2.node.ts b/packages/nodes-base/nodes/Hubspot/V2/HubspotV2.node.ts index 29fc18c015..bdb6e08d4d 100644 --- a/packages/nodes-base/nodes/Hubspot/V2/HubspotV2.node.ts +++ b/packages/nodes-base/nodes/Hubspot/V2/HubspotV2.node.ts @@ -54,7 +54,7 @@ export class HubspotV2 implements INodeType { this.description = { ...baseDescription, group: ['output'], - version: 2, + version: [2, 2.1], subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}', defaults: { name: 'HubSpot', @@ -339,7 +339,18 @@ export class HubspotV2 implements INodeType { async getContactProperties(this: ILoadOptionsFunctions): Promise { const returnData: INodePropertyOptions[] = []; const endpoint = '/properties/v2/contacts/properties'; - const properties = await hubspotApiRequest.call(this, 'GET', endpoint, {}); + + let properties = (await hubspotApiRequest.call(this, 'GET', endpoint, {})) as Array<{ + label: string; + name: string; + }>; + + properties = properties.sort((a, b) => { + if (a.label < b.label) return -1; + if (a.label > b.label) return 1; + return 0; + }); + for (const property of properties) { const propertyName = property.label; const propertyId = property.name; @@ -348,6 +359,7 @@ export class HubspotV2 implements INodeType { value: propertyId, }); } + return returnData; }, // Get all the contact properties to display them to user so that they can @@ -670,7 +682,16 @@ export class HubspotV2 implements INodeType { async getDealProperties(this: ILoadOptionsFunctions): Promise { const returnData: INodePropertyOptions[] = []; const endpoint = '/properties/v2/deals/properties'; - const properties = await hubspotApiRequest.call(this, 'GET', endpoint, {}); + let properties = (await hubspotApiRequest.call(this, 'GET', endpoint, {})) as Array<{ + label: string; + name: string; + }>; + + properties = properties.sort((a, b) => { + if (a.label < b.label) return -1; + if (a.label > b.label) return 1; + return 0; + }); for (const property of properties) { const propertyName = property.label; const propertyId = property.name; @@ -696,6 +717,7 @@ export class HubspotV2 implements INodeType { returnData.push({ name: propertyName, // Hacky way to get the property type need to be parsed to be use in the api + // this is no longer working, properties does not returned in the response value: `${propertyId}|${propertyType}`, }); } @@ -1553,7 +1575,7 @@ export class HubspotV2 implements INodeType { const propertiesValues = additionalFields.propertiesCollection // @ts-ignore .propertiesValues as IDataObject; const properties = propertiesValues.properties as string | string[]; - qs.properties = !Array.isArray(propertiesValues.properties) + qs.property = !Array.isArray(propertiesValues.properties) ? (properties as string).split(',') : properties; qs.propertyMode = snakeCase(propertiesValues.propertyMode as string); @@ -2441,6 +2463,7 @@ export class HubspotV2 implements INodeType { qs.includeAssociations = filters.includeAssociations as boolean; } + //for version 2 if (filters.propertiesCollection) { const propertiesValues = filters.propertiesCollection // @ts-ignore .propertiesValues as IDataObject; @@ -2451,6 +2474,18 @@ export class HubspotV2 implements INodeType { qs.propertyMode = snakeCase(propertiesValues.propertyMode as string); } + //for version > 2 + if (filters.properties) { + const properties = filters.properties as string | string[]; + qs.properties = !Array.isArray(properties) ? properties.split(',') : properties; + } + if (filters.propertiesWithHistory) { + const properties = filters.propertiesWithHistory as string | string[]; + qs.propertiesWithHistory = !Array.isArray(properties) + ? properties.split(',') + : properties; + } + const endpoint = '/deals/v1/deal/paged'; if (returnAll) { responseData = await hubspotApiRequestAllItems.call(