diff --git a/packages/nodes-base/nodes/Hubspot/Hubspot.node.ts b/packages/nodes-base/nodes/Hubspot/Hubspot.node.ts index df86cc0b5f..234da5adbe 100644 --- a/packages/nodes-base/nodes/Hubspot/Hubspot.node.ts +++ b/packages/nodes-base/nodes/Hubspot/Hubspot.node.ts @@ -13,13 +13,14 @@ export class Hubspot extends VersionedNodeType { group: ['output'], subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}', description: 'Consume HubSpot API', - defaultVersion: 2.1, + defaultVersion: 2.2, }; const nodeVersions: IVersionedNodeType['nodeVersions'] = { 1: new HubspotV1(baseDescription), 2: new HubspotV2(baseDescription), 2.1: new HubspotV2(baseDescription), + 2.2: new HubspotV2(baseDescription), }; super(nodeVersions, baseDescription); diff --git a/packages/nodes-base/nodes/Hubspot/V2/EngagementDescription.ts b/packages/nodes-base/nodes/Hubspot/V2/EngagementDescription.ts index 7ae6f4b449..22a746f667 100644 --- a/packages/nodes-base/nodes/Hubspot/V2/EngagementDescription.ts +++ b/packages/nodes-base/nodes/Hubspot/V2/EngagementDescription.ts @@ -411,6 +411,22 @@ export const engagementFields: INodeProperties[] = [ name: 'ownerIds', type: 'string', default: '', + displayOptions: { + show: { + '@version': [{ _cnd: { lt: 2.2 } }], + }, + }, + }, + { + displayName: 'Owner ID', + name: 'ownerId', + type: 'number', + default: 0, + displayOptions: { + show: { + '@version': [{ _cnd: { gte: 2.2 } }], + }, + }, }, { displayName: 'Ticket IDs', diff --git a/packages/nodes-base/nodes/Hubspot/V2/HubspotV2.node.ts b/packages/nodes-base/nodes/Hubspot/V2/HubspotV2.node.ts index 734120b83e..e863795225 100644 --- a/packages/nodes-base/nodes/Hubspot/V2/HubspotV2.node.ts +++ b/packages/nodes-base/nodes/Hubspot/V2/HubspotV2.node.ts @@ -47,7 +47,7 @@ export class HubspotV2 implements INodeType { this.description = { ...baseDescription, group: ['output'], - version: [2, 2.1], + version: [2, 2.1, 2.2], subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}', defaults: { name: 'HubSpot', @@ -2736,13 +2736,19 @@ export class HubspotV2 implements INodeType { ); } + const ownerId = + associations.ownerId && typeof associations.ownerId === 'number' + ? associations.ownerId + : undefined; + const body: { - engagement: { type: string }; + engagement: { type: string; ownerId?: number }; metadata: IDataObject; associations: IDataObject; } = { engagement: { type: type.toUpperCase(), + ownerId, }, metadata: {}, associations: {}, diff --git a/packages/nodes-base/nodes/Hubspot/__test__/Hubspot.node.test.ts b/packages/nodes-base/nodes/Hubspot/__test__/Hubspot.node.test.ts index 964fc9debd..012771eb7f 100644 --- a/packages/nodes-base/nodes/Hubspot/__test__/Hubspot.node.test.ts +++ b/packages/nodes-base/nodes/Hubspot/__test__/Hubspot.node.test.ts @@ -8,6 +8,7 @@ import contacts from './fixtures/contacts.json'; import contactsSearchResult from './fixtures/contacts_search_result.json'; import deals from './fixtures/deals.json'; import dealsSearchResult from './fixtures/deals_search_result.json'; +import engagements from './fixtures/engagements.json'; describe('Hubspot Node', () => { nock.disableNetConnect(); @@ -351,4 +352,24 @@ describe('Hubspot Node', () => { workflowFiles: ['deals.workflow.json'], }); }); + + describe('engagements', () => { + beforeAll(() => { + hubspotNock + .post('/engagements/v1/engagements', function checkOwnerIdIsDefined(body) { + return body.engagement.ownerId === engagements.request[0].engagement.ownerId; + }) + .reply(200, engagements.response[0]) + .post('/engagements/v1/engagements', function checkOwnerIdIsNotDefined(body) { + return body.engagement.ownerId === undefined; + }) + .reply(200, engagements.response[1]); + }); + + afterAll(() => hubspotNock.done()); + + new NodeTestHarness().setupTests({ + workflowFiles: ['engagements.workflow.json'], + }); + }); }); diff --git a/packages/nodes-base/nodes/Hubspot/__test__/engagements.workflow.json b/packages/nodes-base/nodes/Hubspot/__test__/engagements.workflow.json new file mode 100644 index 0000000000..856ab85dbb --- /dev/null +++ b/packages/nodes-base/nodes/Hubspot/__test__/engagements.workflow.json @@ -0,0 +1,189 @@ +{ + "name": "Hubspot - Engagements", + "nodes": [ + { + "parameters": { + "authentication": "appToken", + "resource": "engagement", + "type": "task", + "metadata": { + "body": "Hello world", + "subject": "Title" + }, + "additionalFields": { + "associations": { + "ownerId": 123456789 + } + } + }, + "type": "n8n-nodes-base.hubspot", + "typeVersion": 2.2, + "position": [0, 0], + "id": "942a05ef-f3ed-4511-a00f-0b1e5e1b8a49", + "name": "HubSpot - Engagement - Create with ownerId", + "credentials": { + "hubspotAppToken": { + "id": "vWZfuQawMAWdxKms", + "name": "HubSpot account" + } + } + }, + { + "parameters": { + "authentication": "appToken", + "resource": "engagement", + "type": "task", + "metadata": { + "body": "Hello world", + "subject": "Title" + }, + "additionalFields": {} + }, + "type": "n8n-nodes-base.hubspot", + "typeVersion": 2.2, + "position": [0, 200], + "id": "7fb51d0d-28b5-450d-b910-f6d91e69e934", + "name": "HubSpot - Engagement - Create", + "credentials": { + "hubspotAppToken": { + "id": "vWZfuQawMAWdxKms", + "name": "HubSpot account" + } + } + }, + { + "parameters": {}, + "type": "n8n-nodes-base.manualTrigger", + "typeVersion": 1, + "position": [-220, 600], + "id": "ec9e619e-c75a-41ea-8f54-16827bcd664b", + "name": "When clicking ‘Execute workflow’" + } + ], + "pinData": { + "HubSpot - Engagement - Create with ownerId": [ + { + "json": { + "associationCreateFailures": [], + "engagement": { + "id": 274361144556, + "portalId": 146787276, + "active": true, + "createdAt": 1756127696406, + "lastUpdated": 1756127696406, + "ownerId": 123456789, + "type": "TASK", + "timestamp": 1756127696406, + "allAccessibleTeamIds": [], + "bodyPreview": "Hello world", + "queueMembershipIds": [], + "bodyPreviewIsTruncated": false, + "bodyPreviewHtml": "\n \n \n Hello world\n \n" + }, + "associations": { + "contactIds": [], + "companyIds": [], + "dealIds": [], + "ownerIds": [], + "workflowIds": [], + "ticketIds": [], + "contentIds": [], + "quoteIds": [], + "marketingEventIds": [], + "partnerClientIds": [], + "orderIds": [], + "cartIds": [] + }, + "attachments": [], + "scheduledTasks": [], + "metadata": { + "body": "Hello world", + "status": "NOT_STARTED", + "forObjectType": "OWNER", + "subject": "Title", + "taskType": "TODO", + "reminders": [], + "priority": "NONE", + "isAllDay": false + } + } + } + ], + "HubSpot - Engagement - Create": [ + { + "json": { + "associationCreateFailures": [], + "engagement": { + "id": 274123775164, + "portalId": 146787276, + "active": true, + "createdAt": 1756127766844, + "lastUpdated": 1756127766844, + "type": "TASK", + "timestamp": 1756127766844, + "allAccessibleTeamIds": [], + "bodyPreview": "Hello world", + "queueMembershipIds": [], + "bodyPreviewIsTruncated": false, + "bodyPreviewHtml": "\n \n \n Hello world\n \n" + }, + "associations": { + "contactIds": [], + "companyIds": [], + "dealIds": [], + "ownerIds": [], + "workflowIds": [], + "ticketIds": [], + "contentIds": [], + "quoteIds": [], + "marketingEventIds": [], + "partnerClientIds": [], + "orderIds": [], + "cartIds": [] + }, + "attachments": [], + "scheduledTasks": [], + "metadata": { + "body": "Hello world", + "status": "NOT_STARTED", + "forObjectType": "OWNER", + "subject": "Title", + "taskType": "TODO", + "reminders": [], + "priority": "NONE", + "isAllDay": false + } + } + } + ] + }, + "connections": { + "When clicking ‘Execute workflow’": { + "main": [ + [ + { + "node": "HubSpot - Engagement - Create with ownerId", + "type": "main", + "index": 0 + }, + { + "node": "HubSpot - Engagement - Create", + "type": "main", + "index": 0 + } + ] + ] + } + }, + "active": false, + "settings": { + "executionOrder": "v1" + }, + "versionId": "7b4c4c50-0d21-4857-b36d-6392ee84ab18", + "meta": { + "templateCredsSetupCompleted": true, + "instanceId": "653b28422b2af80d4de68237267b34fdf127ab92f8fb0887c6b0a2be7e7f27c7" + }, + "id": "4TOsSL2vMvJQ86E2", + "tags": [] +} diff --git a/packages/nodes-base/nodes/Hubspot/__test__/fixtures/engagements.json b/packages/nodes-base/nodes/Hubspot/__test__/fixtures/engagements.json new file mode 100644 index 0000000000..002e3a2a76 --- /dev/null +++ b/packages/nodes-base/nodes/Hubspot/__test__/fixtures/engagements.json @@ -0,0 +1,103 @@ +{ + "request": [ + { + "engagement": { "type": "TASK", "ownerId": 123456789 }, + "metadata": { "body": "Hello world", "subject": "Title" }, + "associations": {} + }, + { + "engagement": { "type": "TASK" }, + "metadata": { "body": "Hello world", "subject": "Title" }, + "associations": {} + } + ], + "response": [ + { + "associationCreateFailures": [], + "engagement": { + "id": 274361144556, + "portalId": 146787276, + "active": true, + "createdAt": 1756127696406, + "lastUpdated": 1756127696406, + "ownerId": 123456789, + "type": "TASK", + "timestamp": 1756127696406, + "allAccessibleTeamIds": [], + "bodyPreview": "Hello world", + "queueMembershipIds": [], + "bodyPreviewIsTruncated": false, + "bodyPreviewHtml": "\n \n \n Hello world\n \n" + }, + "associations": { + "contactIds": [], + "companyIds": [], + "dealIds": [], + "ownerIds": [], + "workflowIds": [], + "ticketIds": [], + "contentIds": [], + "quoteIds": [], + "marketingEventIds": [], + "partnerClientIds": [], + "orderIds": [], + "cartIds": [] + }, + "attachments": [], + "scheduledTasks": [], + "metadata": { + "body": "Hello world", + "status": "NOT_STARTED", + "forObjectType": "OWNER", + "subject": "Title", + "taskType": "TODO", + "reminders": [], + "priority": "NONE", + "isAllDay": false + } + }, + { + "associationCreateFailures": [], + "engagement": { + "id": 274123775164, + "portalId": 146787276, + "active": true, + "createdAt": 1756127766844, + "lastUpdated": 1756127766844, + "type": "TASK", + "timestamp": 1756127766844, + "allAccessibleTeamIds": [], + "bodyPreview": "Hello world", + "queueMembershipIds": [], + "bodyPreviewIsTruncated": false, + "bodyPreviewHtml": "\n \n \n Hello world\n \n" + }, + "associations": { + "contactIds": [], + "companyIds": [], + "dealIds": [], + "ownerIds": [], + "workflowIds": [], + "ticketIds": [], + "contentIds": [], + "quoteIds": [], + "marketingEventIds": [], + "partnerClientIds": [], + "orderIds": [], + "cartIds": [] + }, + "attachments": [], + "scheduledTasks": [], + "metadata": { + "body": "Hello world", + "status": "NOT_STARTED", + "forObjectType": "OWNER", + "subject": "Title", + "taskType": "TODO", + "reminders": [], + "priority": "NONE", + "isAllDay": false + } + } + ] +}