mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
⚡ Add custom fields to company:create & company:update (Hubspot) (#1404)
This commit is contained in:
parent
6ffab9860c
commit
39ef004021
|
@ -157,6 +157,41 @@ export const companyFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'The country/region in which the company or organization is located.',
|
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',
|
displayName: 'Description',
|
||||||
name: 'description',
|
name: 'description',
|
||||||
|
@ -474,6 +509,41 @@ export const companyFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'The country/region in which the company or organization is located.',
|
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',
|
displayName: 'Description',
|
||||||
name: 'description',
|
name: 'description',
|
||||||
|
|
|
@ -41,7 +41,6 @@ export async function hubspotApiRequest(this: IHookFunctions | IExecuteFunctions
|
||||||
const credentials = this.getCredentials('hubspotDeveloperApi');
|
const credentials = this.getCredentials('hubspotDeveloperApi');
|
||||||
|
|
||||||
options.qs.hapikey = credentials!.apiKey as string;
|
options.qs.hapikey = credentials!.apiKey as string;
|
||||||
|
|
||||||
return await this.helpers.request!(options);
|
return await this.helpers.request!(options);
|
||||||
} else {
|
} else {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
|
|
@ -526,6 +526,26 @@ export class Hubspot implements INodeType {
|
||||||
}
|
}
|
||||||
return returnData;
|
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<INodePropertyOptions[]> {
|
||||||
|
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 */
|
/* DEAL */
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
@ -1535,6 +1555,18 @@ export class Hubspot implements INodeType {
|
||||||
value: additionalFields.yearFounded,
|
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';
|
const endpoint = '/companies/v2/companies';
|
||||||
responseData = await hubspotApiRequest.call(this, 'POST', endpoint, { properties: body });
|
responseData = await hubspotApiRequest.call(this, 'POST', endpoint, { properties: body });
|
||||||
}
|
}
|
||||||
|
@ -1747,6 +1779,18 @@ export class Hubspot implements INodeType {
|
||||||
value: updateFields.yearFounded,
|
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}`;
|
const endpoint = `/companies/v2/companies/${companyId}`;
|
||||||
responseData = await hubspotApiRequest.call(this, 'PUT', endpoint, { properties: body });
|
responseData = await hubspotApiRequest.call(this, 'PUT', endpoint, { properties: body });
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue