is there a way to check if a call is a POST or a GET ?
What node are you using to receive this?
I'm gonna guess (due to lack of context or pictures or code) you're talking about the http in node?
Attach a debug node set to output the whole message and see what you can gleen from the debug output. There will likely be a property that indicates this.
sorry, yes i use a http in node.
I created a debug node, but do not see get or post in the header
Object
object
_msgid: "7d770295.b78b5c"
topic: ""
payload: object
command: "switchlight"
idx: "1005"
switchcmd: "On"
statusCode: 200
headers: object
x-powered-by: "Express"
access-control-allow-origin: "*"
content-type: "application/json; charset=utf-8"
content-length: "55"
etag: "W/"37-lxv1PRpCI5LeuOxAgTNyWv4sQFc""
date: "Sun, 17 Mar 2019 16:57:18 GMT"
connection: "close"
x-node-red-request-node: "06fc8b26"
responseUrl: "http://192.168.20.32:1880/test?command=switchlight&idx=1005&switchcmd=On"
redirectList: array[0]
As @Steve-Mcl said, try using a debug node set to show the whole message. The debug node is a Swiss Army Knife that will give you lot's of information about your flow. Have a look here:
this was the complete msg object
For an http in you tell it what type to expect don't you? It's in the config.
Hi, I will give some detail info.
In the included flow i support two ways from outsode to turn on a switch (see comment 3 and 4),
So i can receive a http post with a body and a http het with variables in the http url.
Both scenarios POST and GET have a different site to call
http:\xxxx:xx\test and http:\xxxx:xx\test2
The GET AND POST call have both partially different ways to create an MQTT message.
What i want is that i can call my server with only ONE site url, by example
http:\xxxx:xx\test (And NO http:\xxxx:xx\test2) for both POST or GET.
After the call NODE-RED has to detect if it is a POST or GET to makes thinks work like they where separted...
Hope that this is info enough?
[{"id":"87dcf813.641a68","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"b47f58ae.8a7138","type":"mqtt-broker","z":"","name":"mqttdomoticz","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"3bd55103.18210e","type":"mqtt-broker","z":"","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"15","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"43f91110.6822c","type":"mqtt out","z":"87dcf813.641a68","name":"mqtt_domoticz/in","topic":"domoticz/in","qos":"0","retain":"false","broker":"b47f58ae.8a7138","x":1230,"y":120,"wires":[]},{"id":"5ce99120.422b4","type":"inject","z":"87dcf813.641a68","name":"1005 aan","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":120,"wires":[["9e0e34cb.7f1c08"]]},{"id":"9e0e34cb.7f1c08","type":"function","z":"87dcf813.641a68","name":"Maak boodschap 1005 wii en tv lamp Aan","func":"msg.payload = {};\nmsg.payload.command = \"switchlight\";\nmsg.payload.idx = 1005;\nmsg.payload.switchcmd = \"On\";\nreturn msg;","outputs":1,"noerr":0,"x":680,"y":120,"wires":[["43f91110.6822c","1958d1bb.00e10e"]]},{"id":"c48bb42d.574338","type":"http in","z":"87dcf813.641a68","name":"test met get","url":"/test","method":"get","upload":false,"swaggerDoc":"","x":130,"y":700,"wires":[["85560622.9da918","850fb7d7.ca39c8"]]},{"id":"1958d1bb.00e10e","type":"debug","z":"87dcf813.641a68","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1290,"y":360,"wires":[]},{"id":"ae782a10.b76568","type":"comment","z":"87dcf813.641a68","name":"4, http get parameters","info":"http://192.168.20.32:1880/test?command=switchlight&idx=1005&switchcmd=On","x":160,"y":660,"wires":[]},{"id":"95a5498c.e52408","type":"http in","z":"87dcf813.641a68","name":"test met post","url":"/test2","method":"post","upload":false,"swaggerDoc":"","x":130,"y":460,"wires":[["85560622.9da918","c766056b.e22bc8"]]},{"id":"85560622.9da918","type":"http response","z":"87dcf813.641a68","name":"responce post","statusCode":"","headers":{"content-type":"application/json"},"x":200,"y":580,"wires":[]},{"id":"ba41611b.ddc5e","type":"comment","z":"87dcf813.641a68","name":"1. schakelaar zetten met inhoud in bericht","info":"werkt!","x":220,"y":60,"wires":[]},{"id":"514c29eb.afa658","type":"comment","z":"87dcf813.641a68","name":"3. http post met json body","info":"werkt\nifttt activate gateway","x":170,"y":420,"wires":[]},{"id":"c766056b.e22bc8","type":"json","z":"87dcf813.641a68","name":"","property":"payload","action":"","pretty":false,"x":490,"y":460,"wires":[["2e0d0a88.102bf6"]]},{"id":"2e0d0a88.102bf6","type":"change","z":"87dcf813.641a68","name":"convert","rules":[{"t":"set","p":"command","pt":"msg","to":"payload.command","tot":"msg"},{"t":"set","p":"idx","pt":"msg","to":"payload.idx","tot":"msg"},{"t":"set","p":"switchcmd","pt":"msg","to":"payload.switchcmd","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":800,"y":460,"wires":[["43f91110.6822c","1958d1bb.00e10e"]]},{"id":"8248a339.0a3cf","type":"inject","z":"87dcf813.641a68","name":"1005 uit","topic":"","payload":"{\"command\":\"switchlight\",\"idx\":1005,\"switchcmd\":\"Off\"}","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":260,"wires":[["1958d1bb.00e10e","c766056b.e22bc8"]]},{"id":"bc1bd210.b2c29","type":"comment","z":"87dcf813.641a68","name":"2. schakelaar met injector met inhoud","info":"werkt","x":210,"y":220,"wires":[]},{"id":"64ac6cc7.0bd534","type":"http request","z":"87dcf813.641a68","name":"","method":"GET","ret":"obj","paytoqs":false,"url":"http://192.168.20.32:1880/test?command=switchlight&idx=1005&switchcmd=On","tls":"","proxy":"","authType":"basic","x":410,"y":760,"wires":[["850fb7d7.ca39c8"]]},{"id":"586eba26.5678c4","type":"inject","z":"87dcf813.641a68","name":"request","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":780,"wires":[["64ac6cc7.0bd534"]]},{"id":"850fb7d7.ca39c8","type":"function","z":"87dcf813.641a68","name":"convert idx","func":"msg.payload.idx = Number(msg.payload.idx); return msg;","outputs":1,"noerr":0,"x":610,"y":620,"wires":[["2e0d0a88.102bf6"]]},{"id":"ca1e623.681f6a","type":"http request","z":"87dcf813.641a68","name":"","method":"GET","ret":"obj","paytoqs":false,"url":"http://192.168.20.32:1880/test?command=switchlight&idx=1005&switchcmd=On","tls":"","proxy":"","authType":"basic","x":350,"y":1240,"wires":[["2b015d9d.40e362"]]},{"id":"7b71161a.dbd048","type":"inject","z":"87dcf813.641a68","name":"request","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":1240,"wires":[["ca1e623.681f6a"]]},{"id":"2b015d9d.40e362","type":"debug","z":"87dcf813.641a68","name":"test","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"true","targetType":"full","x":710,"y":1240,"wires":[]}]
You should be able to configure separate nodes for the get and post, even though they are on the same address. That is what the Readme says anyway.
How about after the http in nodes, add change nodes & set msg.topic accordingly
e.g. [{"id":"c543757d.8be418","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"f68157f6.8acce8","type":"inject","z":"c543757d.8be418","name":"1005 aan","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":120,"wires":[[]]},{"id":"1c240f72.6e4191","type":"comment","z":"c543757d.8be418","name":"1. schakelaar zetten met inhoud in bericht","info":"werkt!","x":220,"y":60,"wires":[]},{"id":"629b73ac.df890c","type":"comment","z":"c543757d.8be418","name":"2. schakelaar met injector met inhoud","info":"werkt","x":210,"y":220,"wires":[]},{"id":"5f4c019e.8a5cf","type":"http request","z":"c543757d.8be418","name":"","method":"GET","ret":"obj","paytoqs":false,"url":"http://192.168.20.32:1880/test?command=switchlight&idx=1005&switchcmd=On","tls":"","proxy":"","x":350,"y":1240,"wires":[["d0034356.0561c"]]},{"id":"25a5cd36.182e42","type":"inject","z":"c543757d.8be418","name":"request","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":1240,"wires":[["5f4c019e.8a5cf"]]},{"id":"d0034356.0561c","type":"debug","z":"c543757d.8be418","name":"test","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"true","targetType":"full","x":710,"y":1240,"wires":[]},{"id":"64781cbd.17bb04","type":"http in","z":"c543757d.8be418","name":"test met get","url":"/test","method":"get","upload":false,"swaggerDoc":"","x":130,"y":600,"wires":[["a9c6db67.f28258"]]},{"id":"4cf8733f.a1ed1c","type":"http in","z":"c543757d.8be418","name":"test met post","url":"/test","method":"post","upload":false,"swaggerDoc":"","x":130,"y":460,"wires":[["23a0cb30.cf6a84"]]},{"id":"3cdf19c0.a553c6","type":"json","z":"c543757d.8be418","name":"","property":"payload","action":"","pretty":false,"x":450,"y":460,"wires":[["a06cb606.5b9a18"]]},{"id":"e0777929.bbec18","type":"function","z":"c543757d.8be418","name":"convert idx","func":"msg.payload.idx = Number(msg.payload.idx); return msg;","outputs":1,"noerr":0,"x":430,"y":600,"wires":[["a06cb606.5b9a18"]]},{"id":"23a0cb30.cf6a84","type":"change","z":"c543757d.8be418","name":"topic POST","rules":[{"t":"set","p":"topic","pt":"msg","to":"POST","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":460,"wires":[["3cdf19c0.a553c6"]]},{"id":"a9c6db67.f28258","type":"change","z":"c543757d.8be418","name":"topic GET","rules":[{"t":"set","p":"topic","pt":"msg","to":"GET","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":600,"wires":[["e0777929.bbec18"]]},{"id":"a06cb606.5b9a18","type":"switch","z":"c543757d.8be418","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"POST","vt":"str"},{"t":"eq","v":"GET","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":610,"y":520,"wires":[[],[]]}]
i will try it out
FYI, The Http method that was used can be found in msg.req.method
Here is a change
node JSONata expression trick that I like to use when I have an Http input endpoint with multiple (potential) input formats -- i.e. GET, POST, and/or inject a payload (for testing):
The $merge
function takes an array of objects and merges their properties into a single object. In this example, the payload fields are overwritten by any request params with the same name(s) from the POST request, which in turn are overwritten by the same named args on the query string -- of course, your use can may be different.
The big advantage is that the downstream flow does not need to know how the input params were sent.