Rebuild curl command in Node-RED

Hi,

I guess a typical beginner's question: I have a curl command like this:

curl -d "message=TEST" -X POST http://xxxx.xxx

How do I rebuild this in Node-RED? Looks that simple but I didn't manage to get it running, yet... Wanted to use a http node for that but how to configure it and what code do I need to set the payload correctly? At least this
msg.headers={ 'Content-Type': 'application/x-www-form-urlencoded'};

msg.payload = 'message=test';

return msg;

doesn't work as well as

msg.headers={ 'Content-Type': 'application/x-www-form-urlencoded'};

msg.payload ={message:'test'};

return msg;

Thanks for any help...

The POST section in the CURL manual shows what is going on with the -d param

https://curl.haxx.se/docs/manual.html

This translates into a POST request with the payload set to "message=TEST"

I don't think that any other headers would be required since you aren't providing them with curl.

Oh no, it really was a beginner's fault... I forgot to set the HTTP request to "POST"...

So this code works:

msg.headers={ 'Content-Type': 'application/x-www-form-urlencoded'};
msg.payload ="message=Test";
return msg;

Without the Content-Type setting it doesn't... For whatever reason...

If anyone is interested: this code was built to work with the "Text Nachricht" skill from Amazon... Just take this code into a function, use the HTTP Request Node, enter the URL you got from the skill, change Method to "POST" and you're done... Then you get a nice notification on all your Echo devices, the same as you get when you expect a delivery from Amazon...

THANKS

1 Like

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