diff --git a/packages/cli/src/Server.ts b/packages/cli/src/Server.ts index b6a07aab44..ad2a3c1de5 100644 --- a/packages/cli/src/Server.ts +++ b/packages/cli/src/Server.ts @@ -512,11 +512,8 @@ class App { const sessionId = GenericHelpers.getSessionId(req); - // Check if workflow is saved as webhooks can only be tested with saved workflows. - // If that is the case check if any webhooks calls are present we have to wait for and - // if that is the case wait till we receive it. - if (WorkflowHelpers.isWorkflowIdValid(workflowData.id) === true && (runData === undefined || startNodes === undefined || startNodes.length === 0 || destinationNode === undefined)) { - // Webhooks can only be tested with saved workflows + // If webhooks nodes exist and are active we have to wait for till we receive a call + if (runData === undefined || startNodes === undefined || startNodes.length === 0 || destinationNode === undefined) { const credentials = await WorkflowCredentials(workflowData.nodes); const additionalData = await WorkflowExecuteAdditionalData.getBase(credentials); const nodeTypes = NodeTypes(); diff --git a/packages/cli/src/TestWebhooks.ts b/packages/cli/src/TestWebhooks.ts index 61d7213305..45ae624e2b 100644 --- a/packages/cli/src/TestWebhooks.ts +++ b/packages/cli/src/TestWebhooks.ts @@ -129,6 +129,10 @@ export class TestWebhooks { return false; } + if (workflow.id === undefined) { + throw new Error('Webhooks can only be added for saved workflows as an id is needed!'); + } + // Remove test-webhooks automatically if they do not get called (after 120 seconds) const timeout = setTimeout(() => { this.cancelTestWebhook(workflowData.id.toString()); diff --git a/packages/workflow/src/NodeHelpers.ts b/packages/workflow/src/NodeHelpers.ts index 76d8f8b55f..08e9660b99 100644 --- a/packages/workflow/src/NodeHelpers.ts +++ b/packages/workflow/src/NodeHelpers.ts @@ -728,12 +728,6 @@ export function getNodeWebhooks(workflow: Workflow, node: INode, additionalData: return []; } - if (workflow.id === undefined) { - // Workflow has no id which means it is not saved and so webhooks - // will not be enabled - return []; - } - const nodeType = workflow.nodeTypes.getByName(node.type) as INodeType; if (nodeType.description.webhooks === undefined) { @@ -741,12 +735,14 @@ export function getNodeWebhooks(workflow: Workflow, node: INode, additionalData: return []; } + const workflowId = workflow.id || '__UNSAVED__'; + const returnData: IWebhookData[] = []; for (const webhookDescription of nodeType.description.webhooks) { let nodeWebhookPath = workflow.getSimpleParameterValue(node, webhookDescription['path'], 'GET'); if (nodeWebhookPath === undefined) { // TODO: Use a proper logger - console.error(`No webhook path could be found for node "${node.name}" in workflow "${workflow.id}".`); + console.error(`No webhook path could be found for node "${node.name}" in workflow "${workflowId}".`); continue; } @@ -756,13 +752,13 @@ export function getNodeWebhooks(workflow: Workflow, node: INode, additionalData: nodeWebhookPath = nodeWebhookPath.slice(1); } - const path = getNodeWebhookPath(workflow.id, node, nodeWebhookPath); + const path = getNodeWebhookPath(workflowId, node, nodeWebhookPath); const httpMethod = workflow.getSimpleParameterValue(node, webhookDescription['httpMethod'], 'GET'); if (httpMethod === undefined) { // TODO: Use a proper logger - console.error(`The webhook "${path}" for node "${node.name}" in workflow "${workflow.id}" could not be added because the httpMethod is not defined.`); + console.error(`The webhook "${path}" for node "${node.name}" in workflow "${workflowId}" could not be added because the httpMethod is not defined.`); continue; } @@ -771,7 +767,7 @@ export function getNodeWebhooks(workflow: Workflow, node: INode, additionalData: node: node.name, path, webhookDescription, - workflowId: workflow.id, + workflowId, workflowExecuteAdditionalData: additionalData, }); }