mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
✨ Add engagement resource - Hubspot Node (#2615)
* ⚡ Add engagement resource * ⚡ Improvements * 🐛 Fix forObjectType:contact Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
@@ -9,10 +9,16 @@ import {
|
||||
INodePropertyOptions,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
clean,
|
||||
getAssociations,
|
||||
getCallMetadata,
|
||||
getEmailMetadata,
|
||||
getMeetingMetadata,
|
||||
getTaskMetadata,
|
||||
hubspotApiRequest,
|
||||
hubspotApiRequestAllItems,
|
||||
} from './GenericFunctions';
|
||||
@@ -37,6 +43,11 @@ import {
|
||||
dealOperations,
|
||||
} from './DealDescription';
|
||||
|
||||
import {
|
||||
engagementFields,
|
||||
engagementOperations,
|
||||
} from './EngagementDescription';
|
||||
|
||||
import {
|
||||
formFields,
|
||||
formOperations,
|
||||
@@ -137,6 +148,10 @@ export class Hubspot implements INodeType {
|
||||
name: 'Deal',
|
||||
value: 'deal',
|
||||
},
|
||||
{
|
||||
name: 'Engagement',
|
||||
value: 'engagement',
|
||||
},
|
||||
{
|
||||
name: 'Form',
|
||||
value: 'form',
|
||||
@@ -161,6 +176,9 @@ export class Hubspot implements INodeType {
|
||||
// DEAL
|
||||
...dealOperations,
|
||||
...dealFields,
|
||||
// ENGAGEMENT
|
||||
...engagementOperations,
|
||||
...engagementFields,
|
||||
// FORM
|
||||
...formOperations,
|
||||
...formFields,
|
||||
@@ -913,7 +931,7 @@ export class Hubspot implements INodeType {
|
||||
} else {
|
||||
for (let i = 0; i < length; i++) {
|
||||
try {
|
||||
//https://developers.hubspot.com/docs/methods/contacts/create_or_update
|
||||
//https://developers.hubspot.com/docs/methods/contacts/create_or_update
|
||||
if (resource === 'contact') {
|
||||
//https://developers.hubspot.com/docs/methods/companies/create_company
|
||||
if (operation === 'upsert') {
|
||||
@@ -1345,11 +1363,9 @@ export class Hubspot implements INodeType {
|
||||
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;
|
||||
body.limit = this.getNodeParameter('limit', 0) as number;
|
||||
responseData = await hubspotApiRequest.call(this, 'POST', endpoint, body, qs);
|
||||
responseData = responseData.results;
|
||||
}
|
||||
@@ -2123,6 +2139,80 @@ export class Hubspot implements INodeType {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (resource === 'engagement') {
|
||||
//https://legacydocs.hubspot.com/docs/methods/engagements/create_engagement
|
||||
if (operation === 'create') {
|
||||
const type = this.getNodeParameter('type', i) as string;
|
||||
const metadata = this.getNodeParameter('metadata', i) as IDataObject;
|
||||
const associations = this.getNodeParameter('additionalFields.associations', i, {}) as IDataObject;
|
||||
|
||||
if (!Object.keys(metadata).length) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`At least one metadata field needs to set`,
|
||||
);
|
||||
}
|
||||
|
||||
const body: {
|
||||
engagement: { type: string },
|
||||
metadata: IDataObject,
|
||||
associations: IDataObject
|
||||
} = {
|
||||
engagement: {
|
||||
type: type.toUpperCase(),
|
||||
},
|
||||
metadata: {},
|
||||
associations: {},
|
||||
};
|
||||
|
||||
if (type === 'email') {
|
||||
body.metadata = getEmailMetadata(metadata);
|
||||
}
|
||||
|
||||
if (type === 'task') {
|
||||
body.metadata = getTaskMetadata(metadata);
|
||||
}
|
||||
|
||||
if (type === 'meeting') {
|
||||
body.metadata = getMeetingMetadata(metadata);
|
||||
}
|
||||
|
||||
if (type === 'call') {
|
||||
body.metadata = getCallMetadata(metadata);
|
||||
}
|
||||
|
||||
//@ts-ignore
|
||||
body.associations = getAssociations(associations);
|
||||
|
||||
const endpoint = '/engagements/v1/engagements';
|
||||
responseData = await hubspotApiRequest.call(this, 'POST', endpoint, body);
|
||||
}
|
||||
//https://legacydocs.hubspot.com/docs/methods/engagements/get_engagement
|
||||
if (operation === 'delete') {
|
||||
const engagementId = this.getNodeParameter('engagementId', i) as string;
|
||||
const endpoint = `/engagements/v1/engagements/${engagementId}`;
|
||||
responseData = await hubspotApiRequest.call(this, 'DELETE', endpoint, {}, qs);
|
||||
responseData = { success: true };
|
||||
}
|
||||
//https://legacydocs.hubspot.com/docs/methods/engagements/get_engagement
|
||||
if (operation === 'get') {
|
||||
const engagementId = this.getNodeParameter('engagementId', i) as string;
|
||||
const endpoint = `/engagements/v1/engagements/${engagementId}`;
|
||||
responseData = await hubspotApiRequest.call(this, 'GET', endpoint, {}, qs);
|
||||
}
|
||||
//https://legacydocs.hubspot.com/docs/methods/engagements/get-all-engagements
|
||||
if (operation === 'getAll') {
|
||||
const returnAll = this.getNodeParameter('returnAll', 0) as boolean;
|
||||
const endpoint = `/engagements/v1/engagements/paged`;
|
||||
if (returnAll) {
|
||||
responseData = await hubspotApiRequestAllItems.call(this, 'results', 'GET', endpoint, {}, qs);
|
||||
} else {
|
||||
qs.limit = this.getNodeParameter('limit', 0) as number;
|
||||
responseData = await hubspotApiRequest.call(this, 'GET', endpoint, {}, qs);
|
||||
responseData = responseData.results;
|
||||
}
|
||||
}
|
||||
}
|
||||
//https://developers.hubspot.com/docs/methods/forms/forms_overview
|
||||
if (resource === 'form') {
|
||||
//https://developers.hubspot.com/docs/methods/forms/v2/get_fields
|
||||
|
||||
Reference in New Issue
Block a user