fix(HubSpot Node): Assign owner ID (#18753)

This commit is contained in:
yehorkardash
2025-08-27 09:28:46 +03:00
committed by GitHub
parent 51c21e00d0
commit 07db137551
6 changed files with 339 additions and 3 deletions

View File

@@ -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);

View File

@@ -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',

View File

@@ -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: {},

View File

@@ -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'],
});
});
});

View File

@@ -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": "<html>\n <head></head>\n <body>\n Hello world\n </body>\n</html>"
},
"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": "<html>\n <head></head>\n <body>\n Hello world\n </body>\n</html>"
},
"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": []
}

View File

@@ -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": "<html>\n <head></head>\n <body>\n Hello world\n </body>\n</html>"
},
"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": "<html>\n <head></head>\n <body>\n Hello world\n </body>\n</html>"
},
"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
}
}
]
}