How to initialize an integrated flow

Describe the issue/error/question

Hi community! I am having a small issue. most of my flows are executed by a single call to a webhook node. I then do some basic transformation and use execute workflow nodes to pass the data and trigger other flows for different use cases.

I have been having issues while creating this flows cause I can´t find a good way to build and test using the data structure that would come from the execute workflow nodes. I currently use postman to hit the test endpoint with a fake webhook node I later eliminate.

Is there a way to initialize the data for the trigger node without having to hit the endpoint? Example, I take an execution of the main flow, grab the JSON that gets sent to the execute node, paste it in the start node of the next flow, and use that as an initialization until it is active and receives the actual data from the workflow?

Running on npm cloud.

Appreciate any help!

Hi @jpm, welcome to the community :tada:

I would typically use a Function node to mock incoming data without an actual webhook. So disabling the webhook and adding a Function node with code like this should do the trick:

const mock_data = {
  "id": 1,
  "name": "Bulbasaur",
  "additional_names": {
    "english": "Bulbasaur",
    "japanese": "フシギダネ",
    "chinese": "妙蛙种子",
    "french": "Bulbizarre"
  },
  "type": [
    "Grass",
    "Poison"
  ]
};

return [{
  json: mock_data
}];

Simply adjust mock_data in the above example to match your webhook data. The whole workflow would look like so:
image

Example Workflow
{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "1196c69b-01aa-4b41-a16b-75e8c90626d7",
        "options": {}
      },
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        460,
        500
      ],
      "webhookId": "1196c69b-01aa-4b41-a16b-75e8c90626d7",
      "disabled": true
    },
    {
      "parameters": {
        "functionCode": "const mock_data = {\n  \"id\": 1,\n  \"name\": \"Bulbasaur\",\n  \"additional_names\": {\n    \"english\": \"Bulbasaur\",\n    \"japanese\": \"フシギダネ\",\n    \"chinese\": \"妙蛙种子\",\n    \"french\": \"Bulbizarre\"\n  },\n  \"type\": [\n    \"Grass\",\n    \"Poison\"\n  ]\n};\n\nreturn [{\n  json: mock_data\n}];"
      },
      "name": "Mock Data",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        460,
        300
      ]
    },
    {
      "parameters": {},
      "name": "Remaining Workflow",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        680,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Mock Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "Remaining Workflow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mock Data": {
      "main": [
        [
          {
            "node": "Remaining Workflow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

You can simply copy the above JSON and paste it into your canvas.

I hope this helps! Let me know if you have any further queries on this or in case I have missed something.

That´s genius, so simple, don´t know why I didn´t think about it!

I think it would be great UX if there was an option to do this directly in the start node, or in a stand alone node.

But this works great, thanks!

2 Likes

I couldn’t agree more and that’s definitely something the team has on their radar. So this should get more intuitive going forward :slight_smile:

For now I am glad to hear this works for you, thanks a lot for confirming!