fix(Phantombuster Node): Don't send empty objects in request (#22303)

Co-authored-by: RomanDavydchuk <roman.davydchuk@n8n.io>
This commit is contained in:
krisn0x
2025-12-19 18:38:03 +02:00
committed by GitHub
co-authored by RomanDavydchuk
parent e0ab5ba45a
commit cec256f124
6 changed files with 376 additions and 2 deletions
@@ -216,19 +216,31 @@ export class Phantombuster implements INodeType {
const argumentParameters =
((additionalFields.argumentsUi as IDataObject)?.argumentValues as IDataObject[]) ||
[];
body.arguments = argumentParameters.reduce((object, currentValue) => {
const argumentsObj = argumentParameters.reduce((object, currentValue) => {
object[currentValue.key as string] = currentValue.value;
return object;
}, {});
// Only set arguments if not empty as per API requirements
if (Object.keys(argumentsObj).length > 0) {
body.arguments = argumentsObj;
}
delete additionalFields.argumentsUi;
const bonusParameters =
((additionalFields.bonusArgumentUi as IDataObject)
?.bonusArgumentValue as IDataObject[]) || [];
body.bonusArgument = bonusParameters.reduce((object, currentValue) => {
const bonusArgumentObj = bonusParameters.reduce((object, currentValue) => {
object[currentValue.key as string] = currentValue.value;
return object;
}, {});
// Only set bonusArgument if not empty as per API requirements
if (Object.keys(bonusArgumentObj).length > 0) {
body.bonusArgument = bonusArgumentObj;
}
delete additionalFields.bonusArgumentUi;
}
@@ -0,0 +1,95 @@
import { NodeTestHarness } from '@nodes-testing/node-test-harness';
import nock from 'nock';
describe('Phantombuster Node', () => {
const credentials = {
phantombusterApi: {
apiKey: 'test-api-key',
},
};
describe('Launch Agent Without Arguments', () => {
beforeAll(() => {
const mock = nock('https://api.phantombuster.com');
mock
.post('/api/v2/agents/launch', (body) => {
return body.id === 'test-agent-123' && !body.arguments && !body.bonusArgument;
})
.reply(200, { containerId: 'container-456' });
});
new NodeTestHarness().setupTests({
credentials,
workflowFiles: ['launch-without-arguments.workflow.json'],
});
});
describe('Launch Agent With Arguments No Bonus', () => {
beforeAll(() => {
const mock = nock('https://api.phantombuster.com');
mock
.post('/api/v2/agents/launch', (body) => {
return (
body.id === 'test-agent-123' &&
body.arguments &&
body.arguments.testKey === 'testValue' &&
!body.bonusArgument
);
})
.reply(200, { containerId: 'container-456' });
});
new NodeTestHarness().setupTests({
credentials,
workflowFiles: ['launch-with-arguments-no-bonus.workflow.json'],
});
});
describe('Launch Agent With Bonus Arguments', () => {
beforeAll(() => {
const mock = nock('https://api.phantombuster.com');
mock
.post('/api/v2/agents/launch', (body) => {
return (
body.id === 'test-agent-123' &&
body.arguments &&
body.arguments.testKey === 'testValue' &&
body.bonusArgument &&
body.bonusArgument.bonusKey === 'bonusValue'
);
})
.reply(200, { containerId: 'container-456' });
});
new NodeTestHarness().setupTests({
credentials,
workflowFiles: ['launch-with-bonus-arguments.workflow.json'],
});
});
describe('Launch Agent With JSON Arguments', () => {
beforeAll(() => {
const mock = nock('https://api.phantombuster.com');
mock
.post('/api/v2/agents/launch', (body) => {
return (
body.id === 'test-agent-123' &&
body.arguments &&
body.arguments.complexKey === 'complexValue' &&
body.arguments.nestedObject &&
body.arguments.nestedObject.nested === 'value'
);
})
.reply(200, { containerId: 'container-456' });
});
new NodeTestHarness().setupTests({
credentials,
workflowFiles: ['launch-with-json-arguments.workflow.json'],
});
});
});
@@ -0,0 +1,69 @@
{
"name": "Phantombuster Launch With Arguments No Bonus Test",
"nodes": [
{
"parameters": {},
"id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"name": "When clicking 'Execute Workflow'",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [0, 0]
},
{
"parameters": {
"resource": "agent",
"operation": "launch",
"agentId": "test-agent-123",
"jsonParameters": false,
"resolveData": false,
"additionalFields": {
"argumentsUi": {
"argumentValues": [
{
"key": "testKey",
"value": "testValue"
}
]
}
}
},
"id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
"name": "Phantombuster",
"type": "n8n-nodes-base.phantombuster",
"typeVersion": 1,
"position": [220, 0],
"credentials": {
"phantombusterApi": {
"id": "test-cred-id",
"name": "Phantombuster API"
}
}
}
],
"pinData": {
"Phantombuster": [
{
"json": {
"containerId": "container-456"
}
}
]
},
"connections": {
"When clicking 'Execute Workflow'": {
"main": [
[
{
"node": "Phantombuster",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
}
}
@@ -0,0 +1,77 @@
{
"name": "Phantombuster Launch With Bonus Arguments Test",
"nodes": [
{
"parameters": {},
"id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"name": "When clicking 'Execute Workflow'",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [0, 0]
},
{
"parameters": {
"resource": "agent",
"operation": "launch",
"agentId": "test-agent-123",
"jsonParameters": false,
"resolveData": false,
"additionalFields": {
"argumentsUi": {
"argumentValues": [
{
"key": "testKey",
"value": "testValue"
}
]
},
"bonusArgumentUi": {
"bonusArgumentValue": [
{
"key": "bonusKey",
"value": "bonusValue"
}
]
}
}
},
"id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
"name": "Phantombuster",
"type": "n8n-nodes-base.phantombuster",
"typeVersion": 1,
"position": [220, 0],
"credentials": {
"phantombusterApi": {
"id": "test-cred-id",
"name": "Phantombuster API"
}
}
}
],
"pinData": {
"Phantombuster": [
{
"json": {
"containerId": "container-456"
}
}
]
},
"connections": {
"When clicking 'Execute Workflow'": {
"main": [
[
{
"node": "Phantombuster",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
}
}
@@ -0,0 +1,62 @@
{
"name": "Phantombuster Launch With JSON Arguments Test",
"nodes": [
{
"parameters": {},
"id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"name": "When clicking 'Execute Workflow'",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [0, 0]
},
{
"parameters": {
"resource": "agent",
"operation": "launch",
"agentId": "test-agent-123",
"jsonParameters": true,
"resolveData": false,
"additionalFields": {
"argumentsJson": "{\"complexKey\":\"complexValue\",\"nestedObject\":{\"nested\":\"value\"}}"
}
},
"id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
"name": "Phantombuster",
"type": "n8n-nodes-base.phantombuster",
"typeVersion": 1,
"position": [220, 0],
"credentials": {
"phantombusterApi": {
"id": "test-cred-id",
"name": "Phantombuster API"
}
}
}
],
"pinData": {
"Phantombuster": [
{
"json": {
"containerId": "container-456"
}
}
]
},
"connections": {
"When clicking 'Execute Workflow'": {
"main": [
[
{
"node": "Phantombuster",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
}
}
@@ -0,0 +1,59 @@
{
"name": "Phantombuster Launch Without Arguments Test",
"nodes": [
{
"parameters": {},
"id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"name": "When clicking 'Execute Workflow'",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [0, 0]
},
{
"parameters": {
"resource": "agent",
"operation": "launch",
"agentId": "test-agent-123",
"jsonParameters": false,
"resolveData": false
},
"id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
"name": "Phantombuster",
"type": "n8n-nodes-base.phantombuster",
"typeVersion": 1,
"position": [220, 0],
"credentials": {
"phantombusterApi": {
"id": "test-cred-id",
"name": "Phantombuster API"
}
}
}
],
"pinData": {
"Phantombuster": [
{
"json": {
"containerId": "container-456"
}
}
]
},
"connections": {
"When clicking 'Execute Workflow'": {
"main": [
[
{
"node": "Phantombuster",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
}
}