mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 04:34:06 -08:00
⚡ Add custom fields to contact resource on Hubspot-Node (#893)
This commit is contained in:
parent
9fd69bb350
commit
d26cc64163
|
@ -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',
|
||||||
|
|
|
@ -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 });
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue