Skip to content

Commit

Permalink
fix(HubSpot Node): Include properties for contact and deal in getAll …
Browse files Browse the repository at this point in the history
…operation (#8772)
  • Loading branch information
michael-radency authored and netroy committed Mar 6, 2024
1 parent 70cfa7e commit 62ee6a5
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/nodes-base/nodes/Hubspot/Hubspot.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
41 changes: 40 additions & 1 deletion packages/nodes-base/nodes/Hubspot/V2/DealDescription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -603,7 +637,7 @@ export const dealFields: INodeProperties[] = [
name: 'properties',
type: 'multiOptions',
typeOptions: {
loadOptionsMethod: 'getDealPropertiesWithType',
loadOptionsMethod: 'getDealProperties',
},
default: [],
description:
Expand Down Expand Up @@ -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],
},
},
},
],
},
Expand Down
43 changes: 39 additions & 4 deletions packages/nodes-base/nodes/Hubspot/V2/HubspotV2.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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}`,
});
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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(
Expand Down

0 comments on commit 62ee6a5

Please sign in to comment.