1
1
mirror of https://github.com/n8n-io/n8n.git synced 2024-10-26 13:29:14 +03:00

fix(HubSpot Node): Include properties for contact and deal in getAll operation (#8772)

This commit is contained in:
Michael Kret 2024-02-29 17:55:06 +02:00 committed by कारतोफ्फेलस्क्रिप्ट™
parent dbfc2990f5
commit 467fbc712e
3 changed files with 81 additions and 6 deletions

View File

@ -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);

View File

@ -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:
'<p>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.</p><p>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: <code>,</code>.</p>. Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
displayOptions: {
show: {
'@version': [2],
},
},
},
],
},

View File

@ -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<INodePropertyOptions[]> {
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<INodePropertyOptions[]> {
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(