Pass-in URL parameters with value to allow access?

Hi there

Have made a solution where I send an URL to my node-red
/my-testquery?value1=xxx&value2=yyy&value=zzz

How can I add a parameter eg. user=xyz so I can validate if the url is allowed to be processed?

Here is my testflow

[{"id":"b34dd1af.4cb23","type":"template","z":"a67755bf.66e9d8","name":"page","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<html>\n    <head></head>\n    <body>\n        <h1>Got you call</h1>\n    </body>\n</html>","x":650,"y":120,"wires":[["b828f6a6.47d708","710c1ca9.1a4cc4"]]},{"id":"1052941d.efad6c","type":"http in","z":"a67755bf.66e9d8","name":"","url":"/my-testquery","method":"get","upload":false,"swaggerDoc":"","x":490,"y":120,"wires":[["b34dd1af.4cb23"]]},{"id":"b828f6a6.47d708","type":"http response","z":"a67755bf.66e9d8","name":"","statusCode":"","headers":{},"x":810,"y":120,"wires":[]},{"id":"710c1ca9.1a4cc4","type":"debug","z":"a67755bf.66e9d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"req.query","targetType":"msg","statusVal":"","statusType":"auto","x":840,"y":180,"wires":[]}]

And graficaly
image

Change the debug node to show Complete Message and see what is in there when the client asks for a url with parameters.

@grawsom Hello!

From what I understand is that you want to add some functionality in your flow so that you can validate if the username passed in the URL is correct otherwise throw an error.

If that's what you're looking for then following flow is what you need.

[{"id":"3fabdbb9.f58784","type":"http in","z":"daf92697.d2de38","name":"","url":"/my-testquery","method":"get","upload":false,"swaggerDoc":"","x":130,"y":140,"wires":[["6039e16a.3fb0a"]]},{"id":"6bead8d3.0c0228","type":"http response","z":"daf92697.d2de38","name":"","statusCode":"200","headers":{},"x":720,"y":140,"wires":[]},{"id":"6039e16a.3fb0a","type":"switch","z":"daf92697.d2de38","name":"checking user","property":"req.query.user","propertyType":"msg","rules":[{"t":"eq","v":"grawsom","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":360,"y":140,"wires":[["85de7b56.0fc468"],["d907eb5d.b51848"]]},{"id":"85de7b56.0fc468","type":"template","z":"daf92697.d2de38","name":"page","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<html>\n    <head></head>\n    <body>\n        <h1>Got you call</h1>\n    </body>\n</html>","x":550,"y":140,"wires":[["6bead8d3.0c0228"]]},{"id":"11494205.16065e","type":"http response","z":"daf92697.d2de38","name":"","statusCode":"401","headers":{},"x":720,"y":180,"wires":[]},{"id":"d907eb5d.b51848","type":"function","z":"daf92697.d2de38","name":"","func":"msg.payload =`You're not authorized`\nreturn msg;","outputs":1,"noerr":0,"x":550,"y":180,"wires":[["11494205.16065e"]]}]

Best,
-Ravi

@RaviKaushish -just what I was looking for, learning new stuff all the time

1 Like

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