I’m working on an N8N workflow embedded in an app via iframe. I need to grab some URL parameters for a custom node I’m building. But I’m stuck because the usual JavaScript tricks aren’t working.
Here’s what I’ve tried so far:
window.location.href - N8N doesn’t recognize the window object
Using the url module:
const url = require('url');
let params = new url.URLSearchParams('token=example');
console.log(params.get('token'));
This second approach looks promising, but I can’t figure out how to get the actual URL to feed into URLSearchParams.
Does anyone know a way to snag those URL params in a custom N8N node? I’m open to any ideas or workarounds. Thanks!
I’ve encountered a similar issue when working with N8N custom nodes. One approach that worked for me was utilizing the ‘Execute Workflow’ trigger node. This node allows you to pass parameters directly to your workflow, which you can then access in your custom node.
Here’s a brief overview of the process:
Set up an ‘Execute Workflow’ trigger node at the start of your workflow.
In your custom node, access the parameters using $workflow.getNodeParameter(‘parameterName’).
This method bypasses the need for JavaScript’s window object or URL parsing. It’s a bit of a workaround, but it’s reliable and works within N8N’s environment. Let me know if you need more details on implementation.
hey joec, have u tried using the $node[‘Webhook’].json object? it might contain the url params ur lookin for. if not, maybe u could set up a webhook node before ur custom node to capture the full url. worth a shot!
As someone who has worked extensively with N8N, I’ve found that accessing URL parameters in custom nodes can be tricky. An alternative approach is to use an HTTP Request node placed before your custom node, which can capture the entire URL with all parameters. This node can be configured to perform a GET request using a placeholder URL that includes your desired parameters. In your custom node, you can then retrieve the full URL from the previous node and extract parameters as follows: