Unable to query json data from http request

Hi,

We are trying to query json data acquired from GET http request.
I want to use this json data as an API but we are unable to query particular data from the entire data (in json format) received from GET http request.

Kindly refer to the flow for more details.

[{"id":"d8d2976e.972a98","type":"change","z":"223ced0e.462472","name":"Set Headers","rules":[{"t":"set","p":"headers.content-type","pt":"msg","to":"application/json","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":200,"wires":[["2d66c3bc.4e255c"]]}]

Entire json data

Json data after query -

As can be seen from both the screenshots above there is no change in the data before or after query (when we tried to get the data with ip address - 10.0.9.37). If some other parameters are passed in the query (ex., $ in place of ? etc) then that results in an error.

Any help in this regard will be greatly appreciated.

Thanks in advance.

Your flow json is only one node.

Try setting the http node to output a parse object, as it is probably outputting a utf-8 string.

Could you please elaborate a further.

Hi @blob

I think we need you to elaborate further to properly understand your question.

Your question seems to be more about the functionality of the API you are querying, rather than what you then do with the data in Node-RED.

As we know nothing about the API you are using, there isn't much we can do to help.

What is the API? Are you sure it supports the sort of querying you are trying to do? Do you have a link for any documentation of the API?

I'm sorry, I could not be more specific in the previuos post. I just posted a small portion of my flow in the previous post.

[{"id":"223ced0e.462472","type":"tab","label":"Flow 9","disabled":false,"info":""},{"id":"47ecb492.c9102c","type":"http in","z":"223ced0e.462472","name":"","url":"/hello-json","method":"get","upload":false,"swaggerDoc":"","x":380,"y":900,"wires":[["7a118fd5.d3ddc"]]},{"id":"d8d2976e.972a98","type":"change","z":"223ced0e.462472","name":"Set Headers","rules":[{"t":"set","p":"headers","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"headers.content-type","pt":"msg","to":"application/json","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":710,"y":900,"wires":[["2d66c3bc.4e255c"]]},{"id":"2d66c3bc.4e255c","type":"http response","z":"223ced0e.462472","name":"","statusCode":"","headers":{},"x":870,"y":900,"wires":[]},{"id":"7a118fd5.d3ddc","type":"template","z":"223ced0e.462472","name":"","field":"payload","fieldType":"msg","format":"json","syntax":"mustache","template":"{ \"ip\": \"10.0.9.37\", \"rssi\": \"54\", \"tc\": \"37.1\", \"insol\": \"543\", \"imot\": 0.06, \"volt\": \"26.9\", \"modrv\": \"0\", \"hotp\": \"146\", \"timesrc\": \"1\", \"drvprb\": \"\", \"sv30\": \"\", \"sv20\": \"\", \"exmma\": \"\", \"imma\": \"\", \"tsl\": \"\", \"lc\": \"\", \"tcm\": \"\", \"rtc\": \"\", \"hmc\": \"\", \"dte\": \"\", \"dtw\": \"\", \"inclu\": \"\", \"incld\": \"\", \"tpf\": \"\", \"tpd\": \"\", \"mdf\": \"\", \"mdd\": \"\", \"lwf\": \"\", \"lwd\": \"\", \"dorop\": \"\", \"dorcl\": \"\", \"lmc\": \"\", \"dailyt\": \"\", \"incl\": \"\", \"tp\": \"\", \"md\": \"\", \"lw\": \"\", \"dor\": \"\" }, { \"ip\": \"10.0.4.18\", \"rssi\": \"62\", \"tc\": \"33.4\", \"insol\": \"543\", \"imot\": 0, \"volt\": \"24.7\", \"modrv\": \"0\", \"hotp\": \"144\", \"timesrc\": \"1\", \"drvprb\": \"\", \"sv30\": \"\", \"sv20\": \"\", \"exmma\": \"\", \"imma\": \"\", \"tsl\": \"\", \"lc\": \"\", \"tcm\": \"\", \"rtc\": \"\", \"hmc\": \"\", \"dte\": \"\", \"dtw\": \"\", \"inclu\": \"\", \"incld\": \"\", \"tpf\": \"\", \"tpd\": \"\", \"mdf\": \"\", \"mdd\": \"\", \"lwf\": \"\", \"lwd\": \"\", \"dorop\": \"\", \"dorcl\": \"\", \"lmc\": \"\", \"dailyt\": \"\", \"incl\": \"\", \"tp\": \"\", \"md\": \"\", \"lw\": \"\", \"dor\": \"\" }","output":"str","x":560,"y":900,"wires":[["d8d2976e.972a98"]]},{"id":"9da811d0.2c8e8","type":"debug","z":"223ced0e.462472","name":"","active":false,"tosidebar":true,"console":true,"tostatus":false,"complete":"true","targetType":"full","x":530,"y":200,"wires":[]},{"id":"95a1669b.53a008","type":"udp in","z":"223ced0e.462472","name":"receiver","iface":"","port":"12345","ipv":"udp4","multicast":"false","group":"","datatype":"utf8","x":330,"y":200,"wires":[["9da811d0.2c8e8","4235acd8.779a44"]]},{"id":"bc483968.c64bf8","type":"comment","z":"223ced0e.462472","name":"1) UDP messages from sensors & camera are received here","info":"","x":520,"y":140,"wires":[]},{"id":"4235acd8.779a44","type":"function","z":"223ced0e.462472","name":"Fetch_info_data_json","func":"var diship19 = flow.get('diship19') || 0;\nvar diship18 = flow.get('diship18') || 0;\nvar diship20 = flow.get('diship20') || 0;\nvar diship21 = flow.get('diship21') || 0;\nvar diship22 = flow.get('diship22') || 0;\nvar diship23 = flow.get('diship23') || 0;\nvar diship11 = flow.get('diship11') || 0;\nvar diship16 = flow.get('diship16') || 0;\n\nvar infoArr;\nvar info = msg.payload;\nvar errbuf;\nvar drnoArr;\nvar imot;\nvar volt;\nvar insol;\nvar rot_angl;\nvar temp;\nvar motordrv;\nvar hotp;\nvar errorflag;\nvar rssi;\nvar power;\nvar timesrc;\nvar ip;\nvar tc;\n\nvar drvprb;\nvar sv30;\nvar sv20;\nvar ct;\nvar hmc;\nvar dte;\nvar dtw;\nvar inclu;\nvar incld;\nvar tpf;\nvar tpd;\nvar mdf;\nvar mdd;\nvar lwf;\nvar lwd;\nvar dorop;\nvar dorcl;\n\nvar lmc;\nvar dailyt;\nvar incl;\nvar tp;\nvar md;\nvar lw;\nvar dor;\nvar exmma;\nvar imma;\nvar tsl;\nvar lc;\nvar tcm;\nvar rtc;\nvar NULL;\n\n\nconst conditionsArray = [\n    (msg.ip !== diship19), \n    (msg.ip !== diship18),\n    (msg.ip !== diship20),\n    (msg.ip !== diship21), \n    (msg.ip !== diship22),\n    (msg.ip !== diship23),\n    (msg.ip !== diship11),\n    (msg.ip !== diship16),\n    (msg.ip !== \"10.0.0.18\"), \n    (msg.ip !== \"10.0.0.19\"),\n    (msg.ip !== \"10.0.0.20\"),\n    (msg.ip !== \"10.0.0.21\"), \n    (msg.ip !== \"10.0.0.22\"),\n    (msg.ip !== \"10.0.0.23\"),\n    (msg.ip !== \"10.0.65.11\"),\n    (msg.ip !== \"10.0.0.16\"),\n]\n\n\nif (conditionsArray.indexOf(false) === -1) {\n    \n    infoArr = info.split(';');\n    errbuf = Buffer.from(info);\n    imot = infoArr[2]/100;\n    volt = infoArr[3];\n    insol = infoArr[4];\n    temp = infoArr[5];\n    rot_angl = infoArr[6];\n    motordrv = infoArr[8];\n    hotp = infoArr[11];\n    errorflag = infoArr[18];\n    rssi = infoArr[23];\n    power = infoArr[24];\n    timesrc = infoArr[27];\n    //msg.payload = errbuf[0];\n    \n} else {\n    \n    return [null];\n}\n\n    ip = msg.ip;\n    drnoArr = msg.ip.split('.');\n    var dno = drnoArr[3];\n    var num = Number(drnoArr[2]) + Number(64);\n    var rno = String.fromCharCode(num);\n\n\n    if ((errorflag & (Math.pow(2, 3))) > 0) {\n       drvprb = \"Driver problem\";\n    } else {\n        drvprb = \"\";\n    }\n            \n    if ((errorflag & (Math.pow(2, 4))) > 0) {\n       sv30 = \"Supply voltage >30V\";\n    } else {\n        sv30 = \"\";\n    }\n\n    if ((errorflag & (Math.pow(2, 5))) > 0) {\n      sv20 = \"Supply voltage <20V\";\n    } else {\n        sv20 = \"\";\n    }\n        \n    if ((errorflag & (Math.pow(2, 6))) > 0) {\n        ct = \"Chip temperature >70°C\";\n    } else {\n        ct = \"\";\n    }\n\n    if ((errorflag & (Math.pow(2, 0))) > 0) {\n        hmc = \"High motor current\";    \n    } else { \n         if (hmc === undefined){\n            hmc = \"\";\n        } \n    }       \n            \n    if ((errorflag & (Math.pow(2, 8))) > 0) {\n        dte = \"Daily tracking east\";\n    } else {\n        dte = \"\";\n    } \n\n    if ((errorflag & (Math.pow(2, 7))) > 0) {\n        dtw = \"Daily tracking west\";\n    } else {\n        dtw = \"\";\n    }\n\n    if ((errorflag & (Math.pow(2, 9))) > 0) {\n        inclu = \"Inclination up\";\n    } else {\n        inclu = \"\";\n    }\n\n   if ((errorflag & (Math.pow(2, 10))) > 0) {\n       incld = \"Inclination down\";\n   } else {\n       incld = \"\";\n   }\n\n    if ((errorflag & (Math.pow(2, 11))) > 0) {\n        tpf = \"Top flat\";\n    } else {\n        tpf = \"\";\n    }\n\n    if ((errorflag & (Math.pow(2 ^ 12))) > 0) {\n        tpd = \"Top deep\";\n    } else {\n        tpd = \"\";\n    }\n\n    if ((errorflag & (Math.pow(2, 13))) > 0) {\n        mdf = \"Mid flat\";\n    } else {\n        mdf = \"\";\n    }\n\n    if ((errorflag & (Math.pow(2, 14)) > 0)) {\n        mdd = \"Mid deep\";\n    } else {\n        mdd = \"\";\n    }\n\n    if ((errorflag & (Math.pow(2, 15))) > 0) {\n        lwf = \"Low flat\";\n    } else {\n        lwf = \"\";\n    }\n\n    if ((errorflag & (Math.pow(2, 16))) > 0) {\n        lwd = \"Low deep\";\n    } else {\n        lwd = \"\";\n    }\n\n    if ((errorflag & (Math.pow(2, 17))) > 0) {\n        dorop =\"Door open\";\n    } else {\n        dorop = \"\";\n    }\n\n    if ((errorflag & (Math.pow(2, 18))) > 0) {\n        dorcl =\"Door close\";\n    } else {\n        dorcl = \"\";\n    }\n\n\tif ((errorflag & (Math.pow(2, 2))) > 0) {\n\t    lmc = \"Low motor current\";\n\t} else {\n\t    lmc = \"\";\n\t}\n\n    if ((errorflag & (Math.pow(2, 19))) > 0) {\n        dailyt = \"Daily tracking\";\n    } else {\n        dailyt = \"\";\n    }\n\n    if ((errorflag & (Math.pow(2, 20))) > 0) {\n        incl = \"Inclination\";\n    } else {\n        incl = \"\";\n    }\n\n    if ((errorflag & (Math.pow(2, 21))) > 0) {\n        tp = \"Top\";\n    } else {\n        tp = \"\";\n    }\n\n    if ((errorflag & (Math.pow(2, 22))) > 0 ) {\n        md = \"Mid\";\n    } else {\n        md = \"\";\n    }\n    \n\n    if ((errorflag & (Math.pow(2, 23))) > 0) {\n        lw = \"Low\";\n    } else {\n        lw = \"\";\n    }\n\n    if ((errorflag & (Math.pow(2, 24))) > 0) {\n        dor = \"Door\";\n    } else {\n        dor = \"\";\n    }\n    \n    if (((errorflag & (Math.pow(2, 25))) === 0) && (errbuf[0] == 3)) {\n        exmma = \"External MMA8452 failed\";\n    } else {\n        exmma = \"\";\n    }\n\n    if (((errorflag & (Math.pow(2, 26))) === 0) && (errbuf[0] == 3)) {\n        imma = \"Internal MMA8452 failed\";\n    } else {\n        imma = \"\";\n    }\n\n    if (((errorflag & (Math.pow(2, 27))) === 0) && (errbuf[0] == 3)) {\n        tsl = \"TSL256 failed\";\n    } else {\n        tsl = \"\";\n    }\n\n    if (((errorflag & (Math.pow(2, 28))) === 0) && (errbuf[0] == 3)) {\n        lc = \"24LC16 failed\";\n    } else {\n        lc = \"\";\n    }\n\n    if (((errorflag & (Math.pow(2, 29))) === 0) && (errbuf[0] == 3)) {\n        tcm = \"TCM8240 failed\";\n    } else {\n        tcm = \"\";\n    }\n\n    if (((errorflag & (Math.pow(2, 30))) === 0) && (errbuf[0] == 3)) {\n        rtc = \"RTC error\";\n    } else {\n        rtc = \"\";\n    }\n\n\nif (errbuf[0] == 3) {\n  var myJSON = {ip: msg.ip,rssi: rssi,tc: temp,insol: insol,imot: imot,volt: volt,modrv: motordrv,hotp: hotp,timesrc: timesrc,drvprb: drvprb,sv30: sv30,sv20: sv20,exmma: exmma,imma: imma,tsl: tsl,lc: lc,tcm: tcm,rtc: rtc,hmc: hmc,dte: dte,dtw: dtw,inclu: inclu,incld: incld,tpf: tpf,tpd: tpd,mdf: mdf,mdd: mdd,lwf: lwf,lwd: lwd,dorop: dorop,dorcl: dorcl,lmc: lmc,dailyt: dailyt,incl: incl,tp: tp,md: md,lw: lw,dor: dor};\n\n    msg.payload = myJSON;\n    \n    var newMsg = {topic: \"INSERT INTO info (ipadd, imot, volt, insol, rot_angl, mo_drv, hpx, rssi, timesrc, drvprb, sv3, sv2, exmma, imma, tsl, lc, tcm, rtc, hmc, dte, dtw, inclu, incld, tpf, tpd, mdf, mdd, lwf, lwd, lmc, dailyt, incl, tp, md, lw, dno, rno) VALUES ('\"+ ip +\"', '\"+ imot +\"', '\"+ volt +\"', '\"+ insol +\"', '\"+ rot_angl +\"', '\"+ motordrv +\"', '\"+ hotp +\"', '\"+ rssi +\"', '\"+ timesrc +\"', '\"+ drvprb +\"', '\"+ sv30 +\"', '\"+ sv20 +\"', '\"+ exmma +\"', '\"+ imma +\"', '\"+ tsl +\"', '\"+ lc +\"', '\"+ tcm +\"', '\"+ rtc +\"', '\"+ hmc +\"', '\"+ dte +\"', '\"+ dtw +\"', '\"+ inclu +\"', '\"+ incld +\"', '\"+ tpf +\"', '\"+ tpd +\"', '\"+ mdf +\"', '\"+ mdd +\"', '\"+ lwf +\"', '\"+ lwd +\"', '\"+ lmc +\"', '\"+ dailyt +\"', '\"+ incl +\"', '\"+ tp +\"', '\"+ md +\"', '\"+ lw +\"', '\"+ dno +\"', '\"+ rno +\"')\"};\n    return [newMsg, msg];\n    \n}else{\n    \n    return [null,null];\n}\n\n\nreturn [newMsg, msg];\n","outputs":2,"noerr":0,"x":400,"y":300,"wires":[["a54dc2ce.a7b5"],["60aff87e.29ba38","14f2be9d.233cf1"]]},{"id":"e9bfec2.436a11","type":"debug","z":"223ced0e.462472","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":850,"y":320,"wires":[]},{"id":"a54dc2ce.a7b5","type":"mysql","z":"223ced0e.462472","mydb":"59d95a8f.fc3194","name":"","x":700,"y":320,"wires":[["e9bfec2.436a11"]]},{"id":"60aff87e.29ba38","type":"debug","z":"223ced0e.462472","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":551.4285888671875,"y":430,"wires":[]},{"id":"a7ec5679.219a98","type":"json","z":"223ced0e.462472","name":"","property":"payload","action":"str","pretty":true,"x":810,"y":480,"wires":[["fd02d274.853d2","40332400.384cec"]]},{"id":"fd02d274.853d2","type":"DataIn","z":"223ced0e.462472","collection":"c9de68d4.2e9f18","name":"deb","update":false,"path":"/","x":890,"y":540,"wires":[]},{"id":"14f2be9d.233cf1","type":"function","z":"223ced0e.462472","name":"capture data","func":"var index = (flow.get(\"udpindex\") || 0);\nvar udpdata = flow.get(\"udpdata\") || [];\n\nudpdata[index] = msg.payload;\n\nindex++;\nflow.set(\"udpindex\", index);\nflow.set(\"udpdata\", udpdata);\n\n\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":480,"wires":[["ab7d8285.6fb7a"]]},{"id":"ab7d8285.6fb7a","type":"change","z":"223ced0e.462472","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"udpdata","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":600,"wires":[["a7ec5679.219a98"]]},{"id":"40332400.384cec","type":"debug","z":"223ced0e.462472","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":702.5,"y":420,"wires":[]},{"id":"5f4ad968.a8d068","type":"function","z":"223ced0e.462472","name":"","func":"msg.payload = \": \" + msg.payload;\nmsg.payload = '\"DISH\"' + msg.payload;\nmsg.payload = \"{ \" + msg.payload;\nmsg.payload = msg.payload + \" }\";\nreturn msg;","outputs":1,"noerr":0,"x":950,"y":500,"wires":[[]]},{"id":"7590d7fe.f8ab38","type":"http in","z":"223ced0e.462472","name":"","url":"/deb","method":"get","upload":false,"swaggerDoc":"","x":440,"y":740,"wires":[["37df543b.08bb2c"]]},{"id":"5f6fdbec.24fed4","type":"http response","z":"223ced0e.462472","name":"","statusCode":"","headers":{"content-type":"application/json"},"x":750,"y":740,"wires":[]},{"id":"37df543b.08bb2c","type":"DataOut","z":"223ced0e.462472","collection":"c9de68d4.2e9f18","name":"deb","path":"/","error":true,"x":590,"y":740,"wires":[["5f6fdbec.24fed4"]]},{"id":"354a764b.78139a","type":"comment","z":"223ced0e.462472","name":"Sensors data is stored here in json file","info":"","x":1030,"y":620,"wires":[]},{"id":"6600f282.93264c","type":"comment","z":"223ced0e.462472","name":"2) Sensors data is sent to http response","info":"","x":370,"y":700,"wires":[]},{"id":"87b66ea5.57dbf","type":"comment","z":"223ced0e.462472","name":"3) Trying to query data here","info":"Out of the total data received in json file we are trying to query for a particular data, identified by a unique identifier - ip address of the sensor in this case. ","x":315.71429443359375,"y":815.7142944335938,"wires":[]},{"id":"59d95a8f.fc3194","type":"MySQLdatabase","z":"","name":"Ima_21","host":"10.0.64.21","port":"3306","db":"IMATRACK","tz":""},{"id":"c9de68d4.2e9f18","type":"json-db-collection","z":"","name":"deb","collection":"deb","save":true}]

Now I have attached my entire flow here. By going through the flow you might understand what I'm trying to achieve. My flow could be divided into the following parts -

  1. Getting sensor data in UDP and sending it to database and json file.

  2. The stored data in json file is then sent to http response

  3. Trying to query for a particular data.

We are not fetching data from any API, rather we are trying to create an API out of the data we are receiving from the sensors. I think this makes sense.

Now the problematic part is the third part in the flow where out of the total data received in json file we are trying to query for a particular data, identified by a unique identifier - "ip address" of the sensor in this case. But when we try to do so we are getting error and not getting the desired result.

Thanks in advance.

The json in your images are not valid json you are missing the [ ] around the objects. So the file you are storing your json on will not parse correctly.

here is an example, i simulate the file save and read then use the query parameter to query the correct ip using following url.
http://ip:1880/hello_json?ip=10.0.9.37

[{"id":"e4916dbc.e38e7","type":"change","z":"223ced0e.462472","name":"simulate rading file","rules":[{"t":"set","p":"data","pt":"msg","to":"data","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":760,"wires":[["7968e311.2d0214"]]},{"id":"7590d7fe.f8ab38","type":"http in","z":"223ced0e.462472","name":"","url":"/hello_json","method":"get","upload":false,"swaggerDoc":"","x":310,"y":760,"wires":[["e4916dbc.e38e7","8ea981b9.c11f08"]]},{"id":"7968e311.2d0214","type":"change","z":"223ced0e.462472","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.data[ip = $$.payload.ip]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":800,"wires":[["5f6fdbec.24fed4","8ea981b9.c11f08"]]},{"id":"8ea981b9.c11f08","type":"debug","z":"223ced0e.462472","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":680,"y":640,"wires":[]},{"id":"5f6fdbec.24fed4","type":"http response","z":"223ced0e.462472","name":"","statusCode":"","headers":{"content-type":"application/json"},"x":930,"y":760,"wires":[]},{"id":"ab7d8285.6fb7a","type":"change","z":"223ced0e.462472","name":"simulate saving to file","rules":[{"t":"set","p":"data","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":520,"wires":[[]]},{"id":"77622c2b.d76cbc","type":"inject","z":"223ced0e.462472","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"ip\":\"10.0.9.37\",\"rssi\":\"54\",\"tc\":\"37.1\",\"insol\":\"543\",\"imot\":0.06,\"volt\":\"26.9\",\"modrv\":\"0\",\"hotp\":\"146\",\"timesrc\":\"1\"},{\"ip\":\"10.0.9.38\",\"rssi\":\"54\",\"tc\":\"37.1\",\"insol\":\"543\",\"imot\":0.06,\"volt\":\"26.9\",\"modrv\":\"0\",\"hotp\":\"146\",\"timesrc\":\"1\"}]","payloadType":"json","x":440,"y":520,"wires":[["ab7d8285.6fb7a"]]}]

[edit] fixed error

I have also tried with [ ] around the objects but still the same result.

Then please show the flow and debug outputs at each point in the flow, so we have an idea of how you have tried and what data is moving along the flow.

I have already shared my entire flow in one of my previous posts.

As far as data is concerned, I have already had the data hard coded in the template node.

The template node which is available in the third part of the flow where we are trying to query the data.

If anything else is needed kindly let me know.

Thanks for your help.

Having imported your flow, the only bit I can see for where you are creating the HTTP end point is this:

There is no logic in this flow other than seeing the msg.headers property for the response.

Your initial question suggested you had some logic already in place to try to do the querying - but now I see that isn't the case. There is nothing in this flow doing any sort of querying of the data. It just returns what is in the template node.

So what sort of querying do you want it to do?

You share and example of providing ?ip=10.0.9.37 in the url. Within the flow that will mean msg.req.query.ip is set to the value 10.0.9.37. So what do you want to do with that?

I'm repeatedly failing myself to make my point here, that's my mistake. Apologies for that.

But long story short...

I'm looking for something of this sort -

https://cookbook.nodered.org/http/set-request-url-template

We can compare the data in the url below to the entire data I'm receiving from the sensors.
https://jsonplaceholder.typicode.com/posts/

And the post in double curly braces with my ip address

https://jsonplaceholder.typicode.com/posts/{{post}}

As the post id in double curly braces changes so the JSON output from this API in the debug panel changes. I need something similar along these lines - as I change the ip address, the JSON output from the API should display only the data related to the queried ip address. That's it.

The data in the template node is just a small chunk of the entire data to conveniently represent here.

Here is another example this time using a template node to simulate the stored data and output in an object.

You will need to add your node-red ip in the http request node if you want to test using the inject nodes provided.

You can use the url below in a browser
http://your_node_red_ip:1880/1.1.1.1
you can replace 1.1.1.1 with any ip.
if you want to use https you will need to set that up for your node-red. Securing Node-RED : Node-RED

[{"id":"ef5640be.2e9f48","type":"inject","z":"88fadd65b9040724","name":"post id","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"","topic":"","payload":"1.1.1.0","payloadType":"str","x":160,"y":1020,"wires":[["e67a0cc.596d4f"]]},{"id":"e67a0cc.596d4f","type":"change","z":"88fadd65b9040724","name":"","rules":[{"t":"set","p":"post","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":1060,"wires":[["41747a17.54ffd4"]]},{"id":"90bfea22.dd2b98","type":"inject","z":"88fadd65b9040724","name":"post id","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"","topic":"","payload":"1.1.1.1","payloadType":"str","x":160,"y":1060,"wires":[["e67a0cc.596d4f"]]},{"id":"41747a17.54ffd4","type":"http request","z":"88fadd65b9040724","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://192.168.1.25:1880/{{post}}","tls":"","persist":false,"proxy":"","authType":"","x":460,"y":1060,"wires":[["d682318c.36823"]]},{"id":"d682318c.36823","type":"debug","z":"88fadd65b9040724","name":"","active":true,"console":"false","complete":"payload","x":620,"y":1060,"wires":[]},{"id":"8b3282aa.931bf8","type":"http in","z":"88fadd65b9040724","name":"","url":"/:json_hello","method":"get","upload":false,"swaggerDoc":"","x":150,"y":1200,"wires":[["b4ef7f4e.89cc1"]]}]

So are you asking how to construct the right database query using the ip parameter from URL?

I tried with the above approach but got an error as - Invalid Payload

Invalid_payloadJPG

Even tried by directly placing the ip address in the http request node but still the same error.

If you mean json path expression - then yes. To query and fetch only that relevant data for the queried ip.

Hello .. your answer is not very clear.

To recap .. you have some sensors and you save the data to a mySql db. In that db you save the ip and you want to create your own API and query the db based on the ip which will come from the URL query parameter.

Where in this part of your flow are you querying the db ?
image

It should be like this

I dont use the mysql node,, thats why its missing .. but you get the idea

The QUERY DB Function node is there to construct the SQL query

let ip = msg.payload.ip;

// replace <table> with your db table
// replace <ip-column> with your ip column name 
msg.topic = `SELECT * FROM <table> WHERE <ip-column> = '${ip}'`

return msg;

[EDIT]

by visiting, for example http://<node-red-ip>:1880/hello_json?ip=10.0.9.37
will trigger the HTTP in node and in turn the Function node
in the Function node we pick up the ip url query parameter and use it to do an sql query to the db and the result sent to the HTTP out (with header settings application/json)

template

I intend to query (most probably) in the http in node which is the first node in the screenshot above. For the time being I was trying in the url of the browser directly. The template node was introduced just to give this forum an idea of what kind of data I'm dealing with. The template node has nothing to do anything else.

My entire flow -

I'm not querying the Mysql db, I'm just querying the json data I receive in the json db file node (named deb in my flow) . I do save the sensors data in Mysql db which is then used for generating reports in Grafana. That's it. Mysql db has no other purpose.

I will illustrate it graphically what I intend to do in my next post till the graphic representation gets ready .

why are you appending msg.payload in the http request?

where in my example is throwing the error? Which node?

The message node attached to http request is throwing the error - Invalid payload

The inject node eventually sends the ip address to http request node. I did send the ip address initially this way but was throwing error, so I directly appended the ip address to see if it works but still the error.

The url in the browser gives me nothing when everything was done the above way.

Overall picture of what I intend to do.

There are numerous parabolic dishes which send data to the raspberry pi.
We collect the data in our flow in UDP format. We then process the received data from all these dishes and eventually send it to Mysql DB and also store it in json db (node named - deb) in my node red flow.

In short we tend to create an API which could be queried to fetch the requested data that could be used anywhere, for instance we could send this data to a React App or whatever.