{
  "name": "Stubber Reference Flow",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "stubber-reference-flow",
        "authentication": "basicAuth",
        "responseMode": "responseNode",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [-2064, 1216],
      "id": "56b1700b-ae14-4a42-854f-c8a895769f39",
      "name": "Stubmation Start",
      "webhookId": "56b1700b-ae14-4a42-854f-c8a895769f40"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [-1744, 1360],
      "id": "8735705b-198d-4019-bf30-e69de68a4536",
      "name": "Input"
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "leftValue": "={{ $('Input').first().json.body.flow_data.action}}",
                    "rightValue": "[action 01]",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "id": "c808dda2-d31f-4f30-a44c-c6717d11eda9"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "[action 01]"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "34cb6d6d-8c32-43f0-8121-77d887c74b60",
                    "leftValue": "={{ $('Input').first().json.body.flow_data.action}}",
                    "rightValue": "[action 02]",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "[action 02]"
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra"
        }
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [-880, 1312],
      "id": "9b4cc3a3-3284-459c-892b-6a678f6b4b3f",
      "name": "Switch action",
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "jsCode": "// Get all input items\nconst items = $input.all();\n\n// Build the return object.\n// Stubber adds _stubmation.url, a link to this execution on your n8n server.\nconst standard_stubmation_return = {\n  _stubmation: {\n    execution_id: $execution.id,\n    workflow: $workflow.id,\n  },\n};\n\n// Decide what to inject based on input shape\nif (items.length > 1) {\n  // Multiple input items — treat them as an array of result\n  standard_stubmation_return.result = items.map(i => i.json);\n} else if (items.length === 1) {\n  const item = items[0].json;\n\n  if (Array.isArray(item)) {\n    // Single item is itself an array — treat it as array of result\n    standard_stubmation_return.result = item;\n  } else {\n    // Single object — treat it as the result directly\n    standard_stubmation_return.result = item;\n  }\n} else {\n  // No input\n  standard_stubmation_return.result = {\n    message: \"No input provided\"\n  };\n}\n\n// Return as a single item (n8n expects an array)\nreturn [\n  {\n    json: standard_stubmation_return,\n  },\n];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [784, 1408],
      "id": "b4010cda-4bad-4440-b189-bb923d353a9d",
      "name": "Format Standard Stubmation Return"
    },
    {
      "parameters": {
        "jsCode": "// Get all input items\nconst items = $input.all();\n\n// Build the return object.\n// Stubber adds _stubmation.url, a link to this execution on your n8n server.\nconst standard_stubmation_return = {\n  _stubmation: {\n    execution_id: $execution.id,\n    workflow: $workflow.id,\n  },\n};\n\n// Decide what to inject based on input shape\nif (items.length > 1) {\n  // Multiple input items — treat them as an array of result\n  standard_stubmation_return.result = items.map(i => i.json);\n} else if (items.length === 1) {\n  const item = items[0].json;\n\n  if (Array.isArray(item)) {\n    // Single item is itself an array — treat it as array of result\n    standard_stubmation_return.result = item;\n  } else {\n    standard_stubmation_return.result = [item];\n  }\n} else {\n  standard_stubmation_return.result = [];\n}\n\n// Return as a single item (n8n expects an array)\nreturn [\n  {\n    json: standard_stubmation_return,\n  },\n];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [784, 1184],
      "id": "61d7d315-5761-4827-a44d-30d9c8a69039",
      "name": "ARRAY always - Format Standard Stubmation Return"
    },
    {
      "parameters": {
        "jsCode": "// Get all input items\nconst items = $input.all();\n\n// Build the return object.\n// Stubber adds _stubmation.url, a link to this execution on your n8n server.\n// A returned error fails the stubmation task in Stubber.\nconst standard_stubmation_return = {\n  _stubmation: {\n    execution_id: $execution.id,\n    workflow: $workflow.id,\n  },\n};\n\n// Decide what to inject based on input shape\nif (items.length > 1) {\n  // Multiple input items — treat them as an array of errors\n  standard_stubmation_return.error = {\n    message: \"Error\",\n    errors: items.map(i => i.json)\n  };\n} else if (items.length === 1) {\n  const item = items[0].json;\n\n  if (Array.isArray(item)) {\n    // Single item is itself an array — treat it as array of errors\n    standard_stubmation_return.error = {\n      message: \"Error\",\n      errors: item\n    };\n  } else {\n    // Single object — treat it as the error directly\n    standard_stubmation_return.error = item;\n  }\n} else {\n  // No input\n  standard_stubmation_return.error = {\n    message: \"No error input provided\"\n  };\n}\n\n// Return as a single item (n8n expects an array)\nreturn [\n  {\n    json: standard_stubmation_return,\n  },\n];\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [784, 1648],
      "id": "8e683a98-f85a-4895-80a1-227814298262",
      "name": "Format Standard Stubmation Error"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.4,
      "position": [1088, 1536],
      "id": "b9342e5d-964e-4434-8f1e-09d3219cea0e",
      "name": "Respond Stubmation"
    },
    {
      "parameters": {
        "url": "[input URL]",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer [your API token]"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [-32, -64],
      "id": "86ddd554-677c-4d75-806e-de064504b03f",
      "name": "Example HTTP Request with Token",
      "disabled": true,
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [-2288, 1584],
      "id": "b5c56c43-0cd7-45fa-b5b9-390e518b915a",
      "name": "Manual Stubmation Test"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [-2064, 1584],
      "id": "1ccd9f7a-3996-433a-bb58-32ed971556dc",
      "name": "Example 1"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [-2064, 1744],
      "id": "efd11f1a-d487-4591-8163-0075d8b56dcc",
      "name": "Example 2"
    },
    {
      "parameters": {
        "content": "## START HERE\n\nRead **Custom Stubmations** in the Stubber documentation:\nhttps://docs.stubber.com/docs/templates/actions/tasks/stubmation/custom-stubmations\n\nTurn on the workflow before Stubber calls it: Stubber uses the production webhook URL.",
        "height": 200,
        "width": 620
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [-2064, 736],
      "id": "3cb7615f-d7ea-46a0-b6b1-c7a20a77058a",
      "name": "Sticky Note3"
    },
    {
      "parameters": {
        "content": "## Standard Input Data Structure\n\n```\n\"flow_data\": {\n  \"action\": \"[action name]\",\n  \"action_params\": {\n     [Your params here]\n   }\n}```",
        "height": 260,
        "width": 500
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [-2800, 656],
      "id": "c2433a02-eed4-4fd6-bbbd-02929004e308",
      "name": "Sticky Note4"
    },
    {
      "parameters": {
        "content": "## Webhook Basic Auth\n\nChoose a Basic Auth credential on **Stubmation Start** with the same user and password as the Basic credential on the stubmation in the Stubber console.",
        "height": 180,
        "width": 420
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [-2160, 1000],
      "id": "a1f3c2d4-5e6f-4a7b-8c9d-0e1f2a3b4c5d",
      "name": "Sticky Note8"
    },
    {
      "parameters": {
        "content": "## Input Node\n\nThis node can be referenced throughout the flow with : \n\n`{{ $('Input').first().json.body.flow_data.action_params.[var] }}`\n\n",
        "height": 140,
        "width": 600
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [-1744, 1168],
      "id": "df3a6739-1976-4bfc-9fa2-7bee0ef2885c",
      "name": "Sticky Note2"
    },
    {
      "parameters": {
        "content": "## Switch on action names\n\n- always pass an action inside flow data and reuse the single flow for multiple uses on 1 API\n- name the action and the output for clarity",
        "height": 260,
        "width": 580
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [-960, 960],
      "id": "4df53062-2ba9-4463-a5ad-e9454c905338",
      "name": "Sticky Note1"
    },
    {
      "parameters": {
        "content": "## HTTP Request Node Standards\n\n- Use the \"Continue on Error with Error Output\"\n- Connect Error output to the Stubmation error response",
        "width": 420
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [-32, -272],
      "id": "24dff3f3-2ea3-445f-80dc-fcbb2c4a8b48",
      "name": "Sticky Note5"
    },
    {
      "parameters": {
        "content": "## Examples\n\nPin the output of examples here.  \nTo test connect the manual trigger to the example you wish to test.",
        "height": 144,
        "width": 368
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [-2464, 1760],
      "id": "5512ea09-e04a-4f63-b372-2e526a461c86",
      "name": "Sticky Note7"
    }
  ],
  "pinData": {
    "Example 1": [
      {
        "json": {
          "headers": {
            "content-type": "application/json",
            "user-agent": "node-fetch"
          },
          "params": {},
          "query": {},
          "body": {
            "templateuuid": "00000000-0000-0000-0000-000000000001",
            "orguuid": "00000000-0000-0000-0000-000000000002",
            "branch": "draft",
            "context": "default",
            "stubref": "2026-01-01-STUB-ABCD",
            "action_name": "my_action",
            "stubpostuuid": "00000000-0000-0000-0000-000000000003",
            "flow_data": {
              "action": "[action 01]",
              "action_params": {}
            }
          },
          "executionMode": "production"
        }
      }
    ]
  },
  "connections": {
    "Stubmation Start": {
      "main": [[{ "node": "Input", "type": "main", "index": 0 }]]
    },
    "Input": {
      "main": [[{ "node": "Switch action", "type": "main", "index": 0 }]]
    },
    "Switch action": {
      "main": [
        [],
        [],
        [{ "node": "Format Standard Stubmation Error", "type": "main", "index": 0 }],
        [{ "node": "Format Standard Stubmation Error", "type": "main", "index": 0 }]
      ]
    },
    "Format Standard Stubmation Return": {
      "main": [[{ "node": "Respond Stubmation", "type": "main", "index": 0 }]]
    },
    "ARRAY always - Format Standard Stubmation Return": {
      "main": [[{ "node": "Respond Stubmation", "type": "main", "index": 0 }]]
    },
    "Format Standard Stubmation Error": {
      "main": [[{ "node": "Respond Stubmation", "type": "main", "index": 0 }]]
    },
    "Manual Stubmation Test": {
      "main": [[{ "node": "Example 1", "type": "main", "index": 0 }]]
    },
    "Example 1": {
      "main": [[{ "node": "Input", "type": "main", "index": 0 }]]
    },
    "Example 2": {
      "main": [[{ "node": "Input", "type": "main", "index": 0 }]]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "tags": []
}
