Accessing URL parameters in custom N8N nodes: Struggling with browser-side JavaScript methods

I’m trying to get URL parameters in a custom N8N node. The N8N workflow is embedded in my app using an iframe. I’ve tried a few things:

  1. window.location.href doesn’t work because window isn’t recognized.
  2. I tried using the url module:
const url = require('url');
let params = new url.URLSearchParams('token=example');
console.log(params.get('token'));

But I can’t figure out how to get the actual URL to pass to URLSearchParams.

Does anyone know how to access URL params in this situation? I’m stuck and could really use some help. Thanks!

I’ve faced similar challenges with N8N and custom nodes. One approach that worked for me was using the ‘Webhook’ node as an entry point for my workflow. It allows you to create a unique URL that can accept parameters.

You can set up the Webhook node to receive GET or POST requests, then access the parameters using the $input.params object in subsequent nodes. This method bypasses the need to access window or document objects, which aren’t available in N8N’s node execution environment.

For example, if your webhook URL is something like ‘https://your-n8n-instance.com/webhook/abc123’ and you append ‘?token=example’, you can access the token in your custom node with:

const token = $input.params.token;
console.log(token); // Outputs: 'example'

This approach has been reliable for me and might solve your URL parameter access issue without needing browser-side JavaScript methods.

hey there, have u tried using the $node[‘parameter’] syntax in n8n? it might help u access workflow data. also, maybe check if theres a way to pass url params directly to the node when setting up the workflow. just brainstorming here, hope it helps!

Accessing URL parameters in custom N8N nodes can be tricky, especially when dealing with iframe embeds. Have you considered using the ‘Execute Command’ node to run a server-side script that can capture the URL parameters? This approach might bypass the limitations you’re facing with browser-side JavaScript methods.

Alternatively, you could explore N8N’s built-in ‘HTTP Request’ node to make a call to your own API endpoint, which could then return the URL parameters. This method allows you to handle the parameter extraction on your server, avoiding the complexities of accessing the iframe’s URL directly within N8N.

If these options don’t suit your needs, you might want to look into N8N’s webhook functionality. It could provide a way to pass parameters directly into your workflow, circumventing the need to access them from within the custom node itself.