Setting up Webhook connection between 2 servers

I have previously used node-red-contrib-webhookrelay which is really easy to set up and use, although it is a 'paid for' service if you make more than 150 webhook calls per month.

Another forum post inspired me to try and setup a webhook connection between 2 different servers without using webhookrelay, but searching the forum, youtube and even google failed to produce any tutorial or guide how to do this.
I did find this flow which @dceejay wrote, but found it difficult to translate into having client/server on different instances.

Can it be done within the node-RED environment, and if so, has anyone an example?

A webhook is just a fancy name for an http request.

So you need an HTTP In node to create and endpoint that will listen for incoming requests.

And then use the HTTP Request node to send a request. This node will need to be configured with the full address of the instance with the HTTP In node on.

Aah right.
I assume that the HTTP Request node will need the URL formatting as;
https://username:password@mysite.co.uk:1880/test
...where test is the endpoint.

1 Like

Yes, although you wouldn't typically put the username and password into the URL when the node has fields for those things which will store them securely in your credentials file

Ah yes.
Just tried it using the flows as per the gif below, and the client reliable receives the data from the server, but after a few seconds, I start to see errors being logged on the server instance. (Yet the client still continues to receive the data).
Is this how the flows should be structured?

httpgif2

http_error

Or do I need to hang a http response node onto the 'client' http in node to return the status code? That seems to stop the error messages.

http_result

yes you must always have a response to an http in node... (you can of course vary what you send back...)

1 Like

And since it seems to be my lot in life to repeat warnings about security:

  • As Nick says, don't put id/password into a URL as it may expose it to intermediaries and caches.
  • When passing id/password (in a POST body of course, not in the URL), ALWAYS use HTTPS. Otherwise you are leaking credentials to who knows where.

Both are issues reduced if both servers are on a local network of course but it is good practice to assume that the bad people have access to your network (it is more common than many people realise).

It's going to be a SSL connection, but thought it better to get it working without SSL first, and then introduce SSL once I get that working.

Are you sure that my interpretation above, of Nick's advice, is a 'webhook' connection??
I haven't used a websocket node anywhere, and haven't used URL's starting ws://myserver.co....
It's not how I imagined a websocket flow would look like (but what do I know :thinking:)

Webhooks have nothing to do with websockets. They are http requests.

Thanks. I wasn't disputing your advice, I just wasn't sure that I'd interpreted it correctly, and would not wish to leave a forum post that others may look at in the future, that was inaccurate or misleading.
When you know how, it was ridiculously easy to set up, which again concerned me!!

Now engaged SSL, and all is good.

Thanks for the help.

1 Like