Add custom fields to company:create & company:update (Hubspot) (#1404)

This commit is contained in:
Ricardo Espinoza 2021-02-04 09:31:48 -05:00 committed by GitHub
parent 6ffab9860c
commit 39ef004021
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 114 additions and 1 deletions

View file

@ -157,6 +157,41 @@ export const companyFields = [
default: '',
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',
name: 'description',
@ -474,6 +509,41 @@ export const companyFields = [
default: '',
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',
name: 'description',

View file

@ -41,7 +41,6 @@ export async function hubspotApiRequest(this: IHookFunctions | IExecuteFunctions
const credentials = this.getCredentials('hubspotDeveloperApi');
options.qs.hapikey = credentials!.apiKey as string;
return await this.helpers.request!(options);
} else {
// @ts-ignore

View file

@ -526,6 +526,26 @@ export class Hubspot implements INodeType {
}
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 */
/* -------------------------------------------------------------------------- */
@ -1535,6 +1555,18 @@ export class Hubspot implements INodeType {
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';
responseData = await hubspotApiRequest.call(this, 'POST', endpoint, { properties: body });
}
@ -1747,6 +1779,18 @@ export class Hubspot implements INodeType {
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}`;
responseData = await hubspotApiRequest.call(this, 'PUT', endpoint, { properties: body });
}