mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
fix(HubSpot Node): Include properties for contact and deal in getAll operation (#8772)
This commit is contained in:
parent
d1b48ddcac
commit
08e2b068fb
|
@ -14,12 +14,13 @@ export class Hubspot extends VersionedNodeType {
|
||||||
group: ['output'],
|
group: ['output'],
|
||||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||||
description: 'Consume HubSpot API',
|
description: 'Consume HubSpot API',
|
||||||
defaultVersion: 2,
|
defaultVersion: 2.1,
|
||||||
};
|
};
|
||||||
|
|
||||||
const nodeVersions: IVersionedNodeType['nodeVersions'] = {
|
const nodeVersions: IVersionedNodeType['nodeVersions'] = {
|
||||||
1: new HubspotV1(baseDescription),
|
1: new HubspotV1(baseDescription),
|
||||||
2: new HubspotV2(baseDescription),
|
2: new HubspotV2(baseDescription),
|
||||||
|
2.1: new HubspotV2(baseDescription),
|
||||||
};
|
};
|
||||||
|
|
||||||
super(nodeVersions, baseDescription);
|
super(nodeVersions, baseDescription);
|
||||||
|
|
|
@ -588,6 +588,40 @@ export const dealFields: INodeProperties[] = [
|
||||||
description:
|
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.',
|
'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',
|
displayName: 'Deal Properties to Include',
|
||||||
name: 'propertiesCollection',
|
name: 'propertiesCollection',
|
||||||
|
@ -603,7 +637,7 @@ export const dealFields: INodeProperties[] = [
|
||||||
name: 'properties',
|
name: 'properties',
|
||||||
type: 'multiOptions',
|
type: 'multiOptions',
|
||||||
typeOptions: {
|
typeOptions: {
|
||||||
loadOptionsMethod: 'getDealPropertiesWithType',
|
loadOptionsMethod: 'getDealProperties',
|
||||||
},
|
},
|
||||||
default: [],
|
default: [],
|
||||||
description:
|
description:
|
||||||
|
@ -632,6 +666,11 @@ export const dealFields: INodeProperties[] = [
|
||||||
],
|
],
|
||||||
description:
|
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>.',
|
'<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],
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
|
@ -54,7 +54,7 @@ export class HubspotV2 implements INodeType {
|
||||||
this.description = {
|
this.description = {
|
||||||
...baseDescription,
|
...baseDescription,
|
||||||
group: ['output'],
|
group: ['output'],
|
||||||
version: 2,
|
version: [2, 2.1],
|
||||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||||
defaults: {
|
defaults: {
|
||||||
name: 'HubSpot',
|
name: 'HubSpot',
|
||||||
|
@ -339,7 +339,18 @@ export class HubspotV2 implements INodeType {
|
||||||
async getContactProperties(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
async getContactProperties(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
const returnData: INodePropertyOptions[] = [];
|
const returnData: INodePropertyOptions[] = [];
|
||||||
const endpoint = '/properties/v2/contacts/properties';
|
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) {
|
for (const property of properties) {
|
||||||
const propertyName = property.label;
|
const propertyName = property.label;
|
||||||
const propertyId = property.name;
|
const propertyId = property.name;
|
||||||
|
@ -348,6 +359,7 @@ export class HubspotV2 implements INodeType {
|
||||||
value: propertyId,
|
value: propertyId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return returnData;
|
return returnData;
|
||||||
},
|
},
|
||||||
// Get all the contact properties to display them to user so that they can
|
// 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[]> {
|
async getDealProperties(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
const returnData: INodePropertyOptions[] = [];
|
const returnData: INodePropertyOptions[] = [];
|
||||||
const endpoint = '/properties/v2/deals/properties';
|
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) {
|
for (const property of properties) {
|
||||||
const propertyName = property.label;
|
const propertyName = property.label;
|
||||||
const propertyId = property.name;
|
const propertyId = property.name;
|
||||||
|
@ -696,6 +717,7 @@ export class HubspotV2 implements INodeType {
|
||||||
returnData.push({
|
returnData.push({
|
||||||
name: propertyName,
|
name: propertyName,
|
||||||
// Hacky way to get the property type need to be parsed to be use in the api
|
// 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}`,
|
value: `${propertyId}|${propertyType}`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1553,7 +1575,7 @@ export class HubspotV2 implements INodeType {
|
||||||
const propertiesValues = additionalFields.propertiesCollection // @ts-ignore
|
const propertiesValues = additionalFields.propertiesCollection // @ts-ignore
|
||||||
.propertiesValues as IDataObject;
|
.propertiesValues as IDataObject;
|
||||||
const properties = propertiesValues.properties as string | string[];
|
const properties = propertiesValues.properties as string | string[];
|
||||||
qs.properties = !Array.isArray(propertiesValues.properties)
|
qs.property = !Array.isArray(propertiesValues.properties)
|
||||||
? (properties as string).split(',')
|
? (properties as string).split(',')
|
||||||
: properties;
|
: properties;
|
||||||
qs.propertyMode = snakeCase(propertiesValues.propertyMode as string);
|
qs.propertyMode = snakeCase(propertiesValues.propertyMode as string);
|
||||||
|
@ -2441,6 +2463,7 @@ export class HubspotV2 implements INodeType {
|
||||||
qs.includeAssociations = filters.includeAssociations as boolean;
|
qs.includeAssociations = filters.includeAssociations as boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//for version 2
|
||||||
if (filters.propertiesCollection) {
|
if (filters.propertiesCollection) {
|
||||||
const propertiesValues = filters.propertiesCollection // @ts-ignore
|
const propertiesValues = filters.propertiesCollection // @ts-ignore
|
||||||
.propertiesValues as IDataObject;
|
.propertiesValues as IDataObject;
|
||||||
|
@ -2451,6 +2474,18 @@ export class HubspotV2 implements INodeType {
|
||||||
qs.propertyMode = snakeCase(propertiesValues.propertyMode as string);
|
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';
|
const endpoint = '/deals/v1/deal/paged';
|
||||||
if (returnAll) {
|
if (returnAll) {
|
||||||
responseData = await hubspotApiRequestAllItems.call(
|
responseData = await hubspotApiRequestAllItems.call(
|
||||||
|
|
Loading…
Reference in a new issue