Add custom fields to contact resource on Hubspot-Node (#893)

This commit is contained in:
Ricardo Espinoza 2020-08-27 02:20:29 -04:00 committed by GitHub
parent 9fd69bb350
commit d26cc64163
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 68 additions and 0 deletions

View file

@ -171,6 +171,41 @@ export const contactFields = [
type: 'string', type: 'string',
default: '', default: '',
}, },
{
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: 'getContactCustomProperties',
},
default: '',
description: 'Name of the property.',
},
{
displayName: 'Value',
name: 'value',
type: 'string',
default: '',
description: 'Value of the property',
},
],
},
],
},
{ {
displayName: 'Date of Birth', displayName: 'Date of Birth',
name: 'dateOfBirth', name: 'dateOfBirth',

View file

@ -307,6 +307,25 @@ export class Hubspot implements INodeType {
return returnData; return returnData;
}, },
// Get all the contact properties to display them to user so that he can
// select them easily
async getContactCustomProperties(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const endpoint = '/properties/v2/contacts/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;
},
// Get all the contact number of employees options to display them to user so that he can // Get all the contact number of employees options to display them to user so that he can
// select them easily // select them easily
async getContactNumberOfEmployees(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> { async getContactNumberOfEmployees(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
@ -1064,6 +1083,20 @@ export class Hubspot implements INodeType {
value: additionalFields.workEmail, value: additionalFields.workEmail,
}); });
} }
if (additionalFields.customPropertiesUi) {
const customProperties = (additionalFields.customPropertiesUi as IDataObject).customPropertiesValues as IDataObject[];
if (customProperties) {
for (const customProperty of customProperties) {
body.push({
property: customProperty.property,
value: customProperty.value,
});
}
}
}
const endpoint = `/contacts/v1/contact/createOrUpdate/email/${email}`; const endpoint = `/contacts/v1/contact/createOrUpdate/email/${email}`;
responseData = await hubspotApiRequest.call(this, 'POST', endpoint, { properties: body }); responseData = await hubspotApiRequest.call(this, 'POST', endpoint, { properties: body });