How to Create an n8n Webhook to Handle Dynamic URL Parameters?

I’m trying to set up an n8n webhook that can handle any request method (GET, POST, PUT, etc.) and support dynamic URL parameters.

For example, I want the webhook to work for URLs like:

  • http://localhost:5678/webhook/api/gateway/user
  • http://localhost:5678/webhook/api/gateway/user/123
  • http://localhost:5678/webhook/api/gateway/user/123/status
  • http://localhost:5678/webhook/api/gateway/user/123/status/update/more

note:

  1. The number of parameters in the URL is not fixed (it may vary).

You should be able to use “:id” for example(/webhook/api/gateway/user/:id), not sure if you can put multiple after eachother though.

To create an n8n Webhook that can handle dynamic URL parameters, you can try

1. Add a Webhook Node

  1. Open your n8n editor.
  2. Click “+” and select Webhook.
  3. Configure the Webhook node:
  • HTTP Method: GET or POST (based on your use case)
  • Path: Set it to something like /dynamic/:param1/:param2
  • Response Mode: On Received
  • Response Code: 200Example Path:
/api/data/:userId/:orderId
  • Here, :userId and :orderId are dynamic parameters.

2. Access the Dynamic Parameters

  • When a request is sent to the webhook URL, n8n captures the dynamic parameters.
  • To extract them, use {{$json["params"]}} in an Expression.

Example: Extracting Parameters

  • If the URL received is:
https://your-n8n-instance/webhook/api/data/123/456
  • The Webhook Node will output:

json

{
  "params": {
    "userId": "123",
    "orderId": "456"
  }
}

@BramKn Thanks for your reply. The parameters will vary for each request, and my single webhook should support all the following requests made on that particular path.

Example:

  • /webhook/api/gateway/user/:id
  • /webhook/api/gateway/user/all
  • /webhook/api/gateway/login/new/user

@N8N_NATAL_BRAZIL Thanks for your reply. The parameters will vary for each request, and my single webhook should support all the following requests made on that particular path.

Example:

  • /webhook/api/gateway/user/:id
  • /webhook/api/gateway/user/all
  • /webhook/api/gateway/login/new/user

1. Configure the Webhook Node

  1. Add a Webhook Node in n8n.
  2. Set the HTTP Method to * (accepts any request method).
  3. Define the Webhook Path:
  • Use a flexible base path, like:
/api/gateway/*
  • The * allows capturing any subpath beyond /api/gateway/.
  1. Response Mode: On Received

2. Extract Dynamic URL Parameters

Since n8n does not natively parse arbitrary URL paths, you need to extract the path dynamically.

  • The Webhook Node will store the full request URL inside {{$json["headers"]["x-forwarded-path"]}}.

Expression to Extract URL Parameters

Use a Set Node to split the URL path into an array:

{{(() => {
    const fullPath = $json["headers"]["x-forwarded-path"] || "";
    return fullPath.replace("/webhook/api/gateway/", "").split("/");
})()}}

This will convert:

/webhook/api/gateway/user/123/status/update/more

Into:

["user", "123", "status", "update", "more"]

3. Build a Workflow

This workflow: :white_check_mark: Accepts any HTTP method
:white_check_mark: Supports dynamic URL parameters
:white_check_mark: Returns structured response

Workflow Steps

  1. Webhook Node (Capture the request)
  2. Set Node (Extract URL parameters)
  3. Respond to Webhook Node (Return the parsed parameters)

Full Workflow JSON

Here’s a ready-to-import n8n workflow:

{
  "nodes": [
    {
      "parameters": {
        "path": "api/gateway/*",
        "httpMethod": "*",
        "responseMode": "onReceived"
      },
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        400,
        300
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "Method",
              "value": "={{$json[\"headers\"][\"x-method\"]}}"
            },
            {
              "name": "Full Path",
              "value": "={{$json[\"headers\"][\"x-forwarded-path\"]}}"
            },
            {
              "name": "URL Parameters",
              "value": "={{(() => {
                const fullPath = $json[\"headers\"][\"x-forwarded-path\"] || \"\";
                return fullPath.replace(\"/webhook/api/gateway/\", \"\").split(\"/\");
              })()}}"
            }
          ]
        }
      },
      "name": "Extract Parameters",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        600,
        300
      ]
    },
    {
      "parameters": {
        "responseCode": 200,
        "responseBody": "={{$json}}"
      },
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        800,
        300
      ]
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Extract Parameters",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Parameters": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

4. Test the Webhook

  1. Start the Workflow (Click “Execute Workflow”).
  2. Send a request from Postman, cURL, or your browser:Examples:
  • GET http://localhost:5678/webhook/api/gateway/user
  • POST http://localhost:5678/webhook/api/gateway/user/123
  • PUT http://localhost:5678/webhook/api/gateway/user/123/status
  • DELETE http://localhost:5678/webhook/api/gateway/user/123/status/update/more
  1. Response Example:

json

{
  "Method": "GET",
  "Full Path": "/webhook/api/gateway/user/123/status/update/more",
  "URL Parameters": ["user", "123", "status", "update", "more"]
}

Try this, and write the test results.

Thanks

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.