I’m trying to grab some values from the URL in my N8N setup, which is embedded in an app using an iframe. The goal is to use these URL parameters in a custom node for automation stuff.
Here’s what I’ve tried so far:
-
Using window.location.href
, but it seems N8N doesn’t recognize the window
keyword.
-
I also attempted this:
const url = require('url');
let params = new url.URLSearchParams('token=example');
console.log(params.get('token'));
The problem is, I can’t figure out how to get the actual URL to pass into URLSearchParams
.
Does anyone know how to fetch URL params in custom N8N nodes? The usual browser-side JavaScript methods don’t seem to work here. Any ideas or workarounds would be super helpful!
hey sparklinggem, i’ve run into this too. n8n doesn’t let u access browser stuff directly. what worked for me was using the ‘Webhook’ node to catch incoming requests. it gives u all the url params in the json output. then u can use those values in ur custom node. hope this helps!
As someone who’s worked extensively with N8N, I can tell you that accessing URL parameters in custom nodes can be tricky. The browser methods won’t work because N8N runs server-side, not in a browser environment.
Here’s what I’ve found to be effective:
You can access URL parameters through the $node['parameters']
object in your custom node. This object contains all the parameters passed to your node, including those from the URL.
For example, if your URL is like ‘https://your-n8n-instance.com/?token=example’, you can access it like this:
const token = $node['parameters']['token'];
If that doesn’t work, you might need to configure your node to explicitly accept URL parameters. In the node settings, add a new parameter and set its type to ‘string’.
Remember, this approach requires you to set up your workflow to pass these parameters correctly. It’s not as straightforward as browser-side JavaScript, but it’s reliable once set up properly.
Having dealt with similar issues in N8N, I can offer an alternative approach. Since N8N operates server-side, you can’t directly access browser-based URL methods. Instead, consider using the ‘HTTP Request’ node before your custom node.
Set up an HTTP Request node to call an endpoint that echoes back the full URL. Then, in your custom node, you can parse this URL string. Here’s a rough idea:
- Use HTTP Request node to call something like ‘https://httpbin.org/get’
- In your custom node, access the full URL from the previous node’s output
- Parse this URL string using the ‘url’ module
This method gives you access to the full URL, including parameters, without relying on browser-specific APIs. It’s a bit roundabout, but it’s worked well for me in similar scenarios.