I am trying to get the URL parameter from a request and pass it into another URL request.
So my initial request from the the URL is something like: http://xxxxxxx.mybluemix.net/getFlow?parameterCd=00060,00065,00010
And I was to use the "parameterCd" values in another request in the http request node in my flow.
I thought something like this might work - see msg.payload.parameterCd http://waterservices.usgs.gov/nwis/iv/?format=json,1.1&sites=USGS:14330000¶meterCd={{msg.payload.parameterCd}}&siteType=ST
Any ideas? Maybe this is not supported yet.
Answer by knolleary (2799) | Feb 27, 2015 at 05:46 PM
Hi @BrianIBM
as per the sidebar docs of the HTTP In node, the incoming request is available under msg.req
which is the underlying Express request object.
From their docs, the piece you want is msg.req.query. So, in your instance:
msg.req.query.parameterCd
Nick
Answer by BrianIBM (1) | Feb 27, 2015 at 06:35 PM
I was not able to get that to work in the HTTP in node.
I ended up creating a function that creates the entire URL using the msg.req.query. I then set the "url" on the msg.
var url= "http://waterservices.usgs.gov/nwis/iv/?format=json,1.1&siteType=ST&sites=" + msg.req.query.sites + "¶meterCd=" + msg.req.query.parameterCd;
msg.url = url;
return msg;
And in the HTTP in node I just leave the URL field empty and it gets the value from function.
Here is JSON node-red code: [{"id":"b348514d.4cb7b","type":"inject","name":"","topic":"","payload":"{\"parameterCd\":\"00060,00065,00010\"}","payloadType":"string","repeat":"","crontab":"","once":false,"x":118,"y":194,"z":"459cde3c.ba632","wires":[[]]},{"id":"cc1625f2.33e9d8","type":"http request","name":"getRiverFlow","method":"GET","ret":"obj","url":"","x":420,"y":194,"z":"459cde3c.ba632","wires":[["e6c6de1f.19392","5c81ea7d.a37e14"]]},{"id":"e6c6de1f.19392","type":"debug","name":"","active":false,"console":"false","complete":"false","x":452,"y":103,"z":"459cde3c.ba632","wires":[]},{"id":"5c81ea7d.a37e14","type":"function","name":"getFlow","func":"var data = \"{\";\n\nvar timeSeries = msg.payload.value.timeSeries;\n\nvar siteName = \"\";\n\nif (timeSeries.length > 0)\n{\n\tsiteName = timeSeries[0].sourceInfo.siteName;\n\t\n\tdata+= \"\\\"siteName\\\":\\\"\" + siteName + \"\\\"\";\n}\n\nfor (i in timeSeries)\n{\n\tvar varName = timeSeries[i].variable.variableName;\n\t\n\tif (varName.indexOf(\"Temp\") >= 0)\n\t{\n\t\tvarName = \"temp\";\t\n\t}\n\telse if (varName.indexOf(\"flow\") >= 0)\n\t{\n\t\tvarName = \"flow\";\n\t}\n\telse if (varName.indexOf(\"Gage\") >= 0)\n\t{\n\t\tvarName = \"gage\";\n\t}\n\t\n\tdata += \", \\\"\" + varName + \"\\\":\"; \n\t\n\tdata += \"\\\"\" + timeSeries[i].values[0].value[0].value + \"\\\"\";\n}\n\ndata += \"}\"\n\nmsg.payload = data;\n\nreturn msg;","outputs":1,"x":664,"y":193,"z":"459cde3c.ba632","wires":[["aed82af.f5127d8","d65fdd0d.29a02"]]},{"id":"aed82af.f5127d8","type":"debug","name":"","active":true,"console":"false","complete":"false","x":790,"y":96,"z":"459cde3c.ba632","wires":[]},{"id":"99498e0d.66b67","type":"http in","name":"getFlow","url":"/getFlow","method":"get","x":109,"y":356,"z":"459cde3c.ba632","wires":[["56b99498.a9466c"]]},{"id":"d65fdd0d.29a02","type":"http response","name":"","x":882,"y":192,"z":"459cde3c.ba632","wires":[]},{"id":"56b99498.a9466c","type":"function","name":"createUSGSURL","func":"//sites=USGS:14330000\n//parameterCd=00060,00065,00010\n\nvar url= \"http://waterservices.usgs.gov/nwis/iv/?format=json,1.1&siteType=ST&sites=\" + msg.req.query.sites + \"¶meterCd=\" + msg.req.query.parameterCd;\n\nmsg.url = url;\n\nreturn msg;","outputs":1,"x":278,"y":296,"z":"459cde3c.ba632","wires":[["cc1625f2.33e9d8"]]}]
Getting Nick's suggestion to work provides a simple and elegant solution. Just add a function node between the HTTP request and response nodes:
msg.payload=msg.req.query.parameterCd; return msg;
This will emit the required value of parameterCd in response too: http://xxxxxxx.mybluemix.net/getFlow?parameterCd=00060
Answer by MikeAlport (1) | Apr 07, 2016 at 01:16 AM
Pse delete - duplicate
How to get parameter value in HTTP request node using NodeRed 2 Answers
node-red http request options 0 Answers
NodeRed: Cannot read property ' credentials' of null 0 Answers
Can I disable unencrypted access to mybluemix route? Allow only 'https' access? 2 Answers
bluemix security against my application url (SQL injection) 1 Answer