IF webhook url query contains -- not working!

Hi! I’m trying to use a very simple conditional statement: IF the webhook query contains “foo” at ANY part, then respond to webhook: “bar”.

But… it’s not working! The if node doesn’t seem to understand this data :face_with_monocle:

When I hit https://myurl.com/webhook/tst?foo I just get:

(Note: if I delete the IF condition from the workflow, the webhook response gives me the “bar” plain response as expected)

The strangest part is that I am actually seeing that n8n receives the query, but the IF statement for some reason doesn’t process it:

The code:

PS: This is my first topic, I’d like to thank the dev team for this AMAZING and powerful app :clap::clap:… also to let you know that I’m really enjoying n8n’s learning curve! :grin:

Thanks in advance for your help!

Welcome to the community @pbdco!

The reason that it does not work is that it is built for strings but you supply a JavaScript object. There are multiple ways to achieve what you want. One possible solution to, make minimal changes to what you have built already, is to replace the expression on the IF-Node with the following:

{{ Object.keys($node["Webhook"].data["query"]).join(',') }}

That will extract all the keys of the JavaScript object and then combine all of them, separated by a comma. The IF-Node will then work as expected.

Hope that is helpful!

btw. great to hear that you enjoy using n8n!

1 Like

SOLVED! :raised_hands: That worked like a charm

Thank you VERY much for you quick reply @jan ! :pray:
And thank you again for N8N :black_heart:

Best regards!

Glad to hear that it helped. Have fun!

1 Like