HTTP_IN payload

I have a function:

var microW_sensor1 = msg.payload.microW_sensor1;
var microW_sensor2 = msg.payload.microW_sensor2;
var url = `mW1=${microW_sensor1}&mW2=${microW_sensor2}`;
var newMsg = { payload: url };
return newMsg;

which output this: mW1=0&mW2=0.

I need to attach such string to the url (http://10.0.0.40:1880/buz) in a HTTP request node.
Have tried setting the node using the "Append to query string parameters" and also "Send as body request" but it doesn't work.
I also tried to format the url in this way http://10.0.0.40:1880/buz?{{paylod}} without checking any of the above mentioned options, but again looks like I am not achieving the goal to send http://10.0.0.40:1880/buz/mW1=0&mW2=0
On the other side I have an HTTP-in node st as GET and buz:name

Where am I mistaken? How do I get the payload (mW1=0&mW2=0) on the HTTP-IN node?
Thanks for helping

hi .. the Append to query is used in the case that your payload is an object.
since you are doing some manipulation of the parameters, then you could leave the url of the http-request node empty and construct the whole request url yourself using msg.url

var microW_sensor1 = msg.payload.microW_sensor1;
var microW_sensor2 = msg.payload.microW_sensor2;
var params = `mW1=${microW_sensor1}&mW2=${microW_sensor2}`;

msg.url = `http://10.0.0.40:1880/buz?${params}`

Regarding receiving the params in Http-In node .. see example flow
(change the url to match your server)

[{"id":"1c3f0d8e352ee364","type":"http in","z":"54efb553244c241f","name":"","url":"/buz","method":"get","upload":false,"swaggerDoc":"","x":330,"y":2680,"wires":[["d8a7664be0b785db","59aa9d8165272e05"]]},{"id":"d8a7664be0b785db","type":"http response","z":"54efb553244c241f","name":"","statusCode":"","headers":{},"x":580,"y":2680,"wires":[]},{"id":"59aa9d8165272e05","type":"debug","z":"54efb553244c241f","name":"debug 262","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":490,"y":2620,"wires":[]},{"id":"07f76e970ff47079","type":"http request","z":"54efb553244c241f","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":640,"y":2880,"wires":[["10a80b547c666c9f"]]},{"id":"1512e893d5519f30","type":"inject","z":"54efb553244c241f","name":"data","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"microW_sensor1\":123,\"microW_sensor2\":456}","payloadType":"json","x":200,"y":2880,"wires":[["3d3dcee0515912d8"]]},{"id":"3d3dcee0515912d8","type":"function","z":"54efb553244c241f","name":"function 2","func":"var microW_sensor1 = msg.payload.microW_sensor1;\nvar microW_sensor2 = msg.payload.microW_sensor2;\nvar params = `mW1=${microW_sensor1}&mW2=${microW_sensor2}`;\n\nmsg.url = `http://localhost:1880/buz?${params}`\n// msg.rejectUnauthorized = false \n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":410,"y":2880,"wires":[["07f76e970ff47079","f9ba359bd22d64d3"]]},{"id":"10a80b547c666c9f","type":"debug","z":"54efb553244c241f","name":"debug 263","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":850,"y":2880,"wires":[]},{"id":"f9ba359bd22d64d3","type":"debug","z":"54efb553244c241f","name":"debug 264","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":570,"y":2820,"wires":[]}]
1 Like

Thanks a million. It did work perfectly. Really appreciate your help.

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