🔀 Merge branch 'RicardoE105-feature/extend-hubspot'

This commit is contained in:
Jan Oberhauser 2020-08-25 09:52:25 +02:00
commit c22b023df2
2 changed files with 290 additions and 0 deletions

View file

@ -40,6 +40,11 @@ export const contactOperations = [
value: 'getRecentlyCreatedUpdated',
description: 'Get recently created/updated contacts',
},
{
name: 'Search',
value: 'search',
description: 'Search contacts',
},
],
default: 'upsert',
description: 'The operation to perform.',
@ -834,4 +839,242 @@ export const contactFields = [
},
],
},
//*-------------------------------------------------------------------------- */
/* contact:search */
/* -------------------------------------------------------------------------- */
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
resource: [
'contact',
],
operation: [
'search',
],
},
},
default: false,
description: 'If all results should be returned or only up to a given limit.',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
displayOptions: {
show: {
resource: [
'contact',
],
operation: [
'search',
],
returnAll: [
false,
],
},
},
typeOptions: {
minValue: 1,
maxValue: 250,
},
default: 100,
description: 'How many results to return.',
},
{
displayName: 'Filter Groups',
name: 'filterGroupsUi',
type: 'fixedCollection',
default: '',
placeholder: 'Add Filter Group',
typeOptions: {
multipleValues: true,
},
required: false,
displayOptions: {
show: {
resource: [
'contact',
],
operation: [
'search',
],
},
},
options: [
{
name: 'filterGroupsValues',
displayName: 'Filter Group',
values: [
{
displayName: 'Filters',
name: 'filtersUi',
type: 'fixedCollection',
default: '',
placeholder: 'Add Filter',
typeOptions: {
multipleValues: true,
},
required: false,
options: [
{
name: 'filterValues',
displayName: 'Filter',
values: [
{
displayName: 'Property Name',
name: 'propertyName',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getContactProperties',
},
default: '',
},
{
displayName: 'Operator',
name: 'operator',
type: 'options',
options: [
{
name: 'Equal',
value: 'EQ',
},
{
name: 'Not Equal',
value: 'NEQ',
},
{
name: 'Less Than',
value: 'LT',
},
{
name: 'Less Than Or Equal',
value: 'LTE',
},
{
name: 'Greater Than',
value: 'GT',
},
{
name: 'Greater Than Or Equal',
value: 'GTE',
},
{
name: 'Is Known',
value: 'HAS_PROPERTY',
},
{
name: 'Is Unknown',
value: 'NOT_HAS_PROPERTY',
},
{
name: 'Contains Exactly',
value: 'CONSTAIN_TOKEN',
},
{
name: `Doesn't Contain Exactly`,
value: 'NOT_CONSTAIN_TOKEN',
},
],
default: 'EQ',
},
{
displayName: 'Value',
name: 'value',
displayOptions: {
hide: {
operator: [
'HAS_PROPERTY',
'NOT_HAS_PROPERTY',
],
},
},
type: 'string',
default: '',
},
],
}
],
description: 'Use filters to limit the results to only CRM objects with matching property values. More info <a href="https://developers.hubspot.com/docs/api/crm/search">here</a>',
},
],
}
],
description: `When multiple filters are provided within a filterGroup, they will be combined using a logical AND operator.<br>
When multiple filterGroups are provided, they will be combined using a logical OR operator.<br>
The system supports a maximum of three filterGroups with up to three filters each.<br>
More info <a href="https://developers.hubspot.com/docs/api/crm/search">here</a>`
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: [
'contact',
],
operation: [
'search',
],
},
},
options: [
{
displayName: 'Direction',
name: 'direction',
type: 'options',
options: [
{
name: 'ASC',
value: 'ASCENDING',
},
{
name: 'DESC',
value: 'DESCENDING',
},
],
default: 'DESCENDING',
description: 'Defines the direction in which search results are ordered. Default value is DESC.',
},
{
displayName: 'Fields',
name: 'properties',
type: 'multiOptions',
typeOptions: {
loadOptionsMethod: 'getContactProperties',
},
default: [
'firstname',
'lastname',
'email',
],
description: `Used to include specific company properties in the results.<br/>
By default, the results will only include company ID and will not include the values for any properties for your companys.<br/>
Including this parameter will include the data for the specified property in the results.<br/>
You can include this parameter multiple times to request multiple properties separed by ,.`,
},
{
displayName: 'Query',
name: 'query',
type: 'string',
default: '',
description: 'Perform a text search against all property values for an object type',
},
{
displayName: 'Sort By',
name: 'sortBy',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getContactProperties',
},
default: 'createdate',
},
],
},
] as INodeProperties[];

View file

@ -1166,6 +1166,53 @@ export class Hubspot implements INodeType {
const endpoint = `/contacts/v1/contact/vid/${contactId}`;
responseData = await hubspotApiRequest.call(this, 'DELETE', endpoint);
}
//https://developers.hubspot.com/docs/api/crm/search
if (operation === 'search') {
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
const returnAll = this.getNodeParameter('returnAll', 0) as boolean;
const filtersGroupsUi = this.getNodeParameter('filterGroupsUi', i) as IDataObject;
const sortBy = additionalFields.sortBy || 'createdate';
const direction = additionalFields.direction || 'DESCENDING';
const body: IDataObject = {
sorts: [
{
propertyName: sortBy,
direction,
},
],
};
if (filtersGroupsUi) {
const filterGroupValues = (filtersGroupsUi as IDataObject).filterGroupsValues as IDataObject[];
if (filterGroupValues) {
body.filterGroups = [];
for (const filterGroupValue of filterGroupValues) {
if (filterGroupValue.filtersUi) {
const filterValues = (filterGroupValue.filtersUi as IDataObject).filterValues as IDataObject[];
if (filterValues) {
//@ts-ignore
body.filterGroups.push({ filters: filterValues });
}
}
}
}
}
Object.assign(body, additionalFields);
const endpoint = '/crm/v3/objects/contacts/search';
if (returnAll) {
responseData = await hubspotApiRequestAllItems.call(this, 'results', 'POST', endpoint, body, qs);
} else {
qs.count = this.getNodeParameter('limit', 0) as number;
responseData = await hubspotApiRequest.call(this, 'POST', endpoint, body, qs);
responseData = responseData.results;
}
}
}
//https://developers.hubspot.com/docs/methods/companies/companies-overview
if (resource === 'company') {