Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🪝 Add Any/All method matching for webhooks #5879

Closed
wants to merge 2 commits into from

Conversation

pemontto
Copy link
Contributor

@pemontto pemontto commented Apr 1, 2023

Common cause of issues where the webhook method doesn't match the sending service. Allow a single webhook trigger to match all methods.

Probably a suboptimal solution, but works OK in testing:

Expand workflow JSON
{
  "nodes": [
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "res",
              "value": "={{ $prevNode.name }}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set1",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        800,
        220
      ]
    },
    {
      "parameters": {
        "path": "1e6d2b16-3105-4d3c-a456-ed889a0e39cc",
        "responseMode": "lastNode",
        "responseData": "allEntries",
        "options": {}
      },
      "name": "1: GET",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        460,
        -40
      ],
      "webhookId": "1e6d2b16-3105-4d3c-a456-ed889a0e39cc"
    },
    {
      "parameters": {
        "httpMethod": "PUT",
        "path": "1e6d2b16-3105-4d3c-a456-ed889a0e39cc",
        "responseMode": "lastNode",
        "responseData": "allEntries",
        "options": {}
      },
      "name": "1: PUT",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        360,
        80
      ],
      "webhookId": "1e6d2b16-3105-4d3c-a456-ed889a0e39cc"
    },
    {
      "parameters": {
        "httpMethod": "*",
        "path": "/:variable1/path/:variable2",
        "responseMode": "lastNode",
        "responseData": "allEntries",
        "options": {}
      },
      "name": "Dynamic: All",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        460,
        480
      ],
      "webhookId": "413cb7ac-87e8-4bbf-a215-c1403657baae"
    },
    {
      "parameters": {
        "httpMethod": "*",
        "path": "1e6d2b16-3105-4d3c-a456-ed889a0e39cc",
        "responseMode": "lastNode",
        "responseData": "allEntries",
        "options": {}
      },
      "name": "1: All",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        620,
        -80
      ],
      "webhookId": "1e6d2b16-3105-4d3c-a456-ed889a0e39cc"
    },
    {
      "parameters": {
        "path": "/:variable1/path/:variable2",
        "responseMode": "lastNode",
        "responseData": "allEntries",
        "options": {}
      },
      "name": "Dynamic: Get",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        360,
        360
      ],
      "webhookId": "413cb7ac-87e8-4bbf-a215-c1403657baae"
    },
    {
      "parameters": {
        "httpMethod": "*",
        "path": "c0ea031a-703b-41cb-9121-d41fe6bb649c",
        "responseMode": "lastNode",
        "responseData": "allEntries",
        "options": {}
      },
      "name": "2: All",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        300,
        220
      ],
      "webhookId": "c0ea031a-703b-41cb-9121-d41fe6bb649c"
    }
  ],
  "connections": {
    "1: GET": {
      "main": [
        [
          {
            "node": "Set1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "1: PUT": {
      "main": [
        [
          {
            "node": "Set1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Dynamic: All": {
      "main": [
        [
          {
            "node": "Set1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "1: All": {
      "main": [
        [
          {
            "node": "Set1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Dynamic: Get": {
      "main": [
        [
          {
            "node": "Set1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "2: All": {
      "main": [
        [
          {
            "node": "Set1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

@n8n-assistant n8n-assistant bot added community Authored by a community member core Enhancement outside /nodes-base and /editor-ui node/improvement New feature or request labels Apr 1, 2023
@codecov
Copy link

codecov bot commented Apr 1, 2023

Codecov Report

Patch coverage: 10.00% and project coverage change: -0.01 ⚠️

Comparison is base (9ada331) 15.02% compared to head (eacc503) 15.02%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5879      +/-   ##
==========================================
- Coverage   15.02%   15.02%   -0.01%     
==========================================
  Files        2476     2476              
  Lines      113455   113469      +14     
  Branches    17744    17748       +4     
==========================================
  Hits        17051    17051              
- Misses      95823    95837      +14     
  Partials      581      581              
Impacted Files Coverage Δ
packages/nodes-base/nodes/Wait/Wait.node.ts 0.00% <ø> (ø)
packages/nodes-base/nodes/Webhook/Webhook.node.ts 0.00% <ø> (ø)
packages/cli/src/ActiveWorkflowRunner.ts 44.70% <10.00%> (-0.59%) ⬇️

... and 1 file with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@luizeof
Copy link
Contributor

luizeof commented Apr 2, 2023

I still think that having 2 or more webhooks with the same address and different methods as it is today is the best way to deal with inconsistencies of this type.

@pemontto
Copy link
Contributor Author

pemontto commented Apr 2, 2023

I still think that having 2 or more webhooks with the same address and different methods as it is today is the best way to deal with inconsistencies of this type.

I can see multiple nodes being better in some circumstances, however if I'm simulating an API, I want GET, PUT, PATCH, POST, DELETE on an endpoint. Without this change, if for example I want endpoints for user, post, and comment I'll need 15 trigger nodes... that's unwieldy.

@pemontto
Copy link
Contributor Author

Closing, implemented in #9086

@pemontto pemontto closed this Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Authored by a community member core Enhancement outside /nodes-base and /editor-ui node/improvement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants