Digital Developer Conference: a FREE half-day online conference focused on AI & Cloud – North America: Nov 2 – India: Nov 9 – Europe: Nov 14 – Asia Nov 23 Register now

Close outline
  • United States
IBM?
  • Site map
IBM?
  • Marketplace

  • Close
    Search
  • Sign in
    • Sign in
    • Register
  • IBM Navigation
IBM Developer Answers
  • Spaces
    • Blockchain
    • IBM Cloud platform
    • Internet of Things
    • Predictive Analytics
    • Watson
    • See all spaces
  • Tags
  • Users
  • Badges
  • FAQ
  • Help
Close

Name

Community

  • Learn
  • Develop
  • Connect

Discover IBM

  • ConnectMarketplace
  • Products
  • Services
  • Industries
  • Careers
  • Partners
  • Support
10.190.13.195

Refine your search by using the following advanced search options.

Criteria Usage
Questions with keyword1 or keyword2 keyword1 keyword2
Questions with a mandatory word, e.g. keyword2 keyword1 +keyword2
Questions excluding a word, e.g. keyword2 keyword1 -keyword2
Questions with keyword(s) and a specific tag keyword1 [tag1]
Questions with keyword(s) and either of two or more specific tags keyword1 [tag1] [tag2]
To search for all posts by a user or all posts with a specific tag, start typing and choose from the suggestion list. Do not use a plus or minus sign with a tag, e.g., +[tag1].
  • Ask a question

How to get parameter value in HTTP request node using NodeRed

270000WFM3 gravatar image
Question by BrianIBM  (1) | Feb 27, 2015 at 12:57 PM node-redhttpibmcloudurlparameters

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.

People who like this

  0
Comment
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster

4 answers

  • Sort: 
120000NH9U gravatar image

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

Comment

People who like this

  0   Share
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
270000WFM3 gravatar image

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"]]}]

Comment

People who like this

  0   Show 1   Share
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
3100004C46 gravatar image MikeAlport (1)   Apr 07, 2016 at 01:20 AM 0
Share

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

3100004C46 gravatar image

Answer by MikeAlport (1) | Apr 07, 2016 at 01:16 AM

Pse delete - duplicate

Comment

People who like this

  0   Share
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
3100004C46 gravatar image

Answer by MikeAlport (1) | Apr 07, 2016 at 01:17 AM

pse delete

Comment

People who like this

  0   Share
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster

Follow this question

47 people are following this question.

Answers

Answers & comments

Related questions

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

  • Contact
  • Privacy
  • IBM Developer Terms of use
  • Accessibility
  • Report Abuse
  • Cookie Preferences

Powered by AnswerHub

Authentication check. Please ignore.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • API Connect
  • Analytic Hybrid Cloud Core
  • Application Performance Management
  • Appsecdev
  • BPM
  • Blockchain
  • Business Transaction Intelligence
  • CAPI
  • CAPI SNAP
  • CICS
  • Cloud Analytics
  • Cloud Automation
  • Cloud Object Storage
  • Cloud marketplace
  • Collaboration
  • Content Services (ECM)
  • Continuous Testing
  • Courses
  • Customer Experience Analytics
  • DB2 LUW
  • Data and AI
  • DataPower
  • Decision Optimization
  • DevOps Build
  • DevOps Services
  • Developers IBM MX
  • Digital Commerce
  • Digital Experience
  • Finance
  • Global Entrepreneur Program
  • Hadoop
  • Hybrid Cloud Core
  • Hyper Protect
  • IBM Cloud platform
  • IBM Design
  • IBM Forms Experience Builder
  • IBM Maximo Developer
  • IBM StoredIQ
  • IBM StoredIQ-Cartridges
  • IIDR
  • ITOA
  • InformationServer
  • Integration Bus
  • Internet of Things
  • Kenexa
  • Linux on Power
  • LinuxONE
  • MDM
  • Mainframe
  • Messaging
  • Node.js
  • ODM
  • Open
  • PartnerWorld Developer Support
  • PowerAI
  • PowerVC
  • Predictive Analytics
  • Product Insights
  • PureData for Analytics
  • Push
  • QRadar App Development
  • Run Book Automation
  • Search Insights
  • Security Core
  • Storage
  • Storage Core
  • Streamsdev
  • Supply Chain Business Network
  • Supply Chain Insights
  • Swift
  • UBX Capture
  • Universal Behavior Exchange
  • UrbanCode
  • WASdev
  • WSRR
  • Watson
  • Watson Campaign Automation
  • Watson Content Hub
  • Watson Marketing Insights
  • dW Answers Help
  • dW Premium
  • developerWorks Sandbox
  • developerWorks Team
  • Watson Health
  • More
  • Tags
  • Questions
  • Users
  • Badges