HowTo POST HTTP request Synology Chat

My goal is to send an HTTP command to the Synology Chat bot.
In Synology's cookbook, it is described as follows.

Place the JSON string after the payload application / x-www-form-urlencoded data parameter to the webhook url. Example:

POST https://DS_IP/webapi/entry.cgi?api=SYNO.Chat.External&XXXXX Content-Type: application/x-www-form-urlencoded payload=%7B%22text%22%3A%22This%20is%20a%20test.%22%7D

Below is an example of CURL:

curl -X POST \ --data-urlencode 'payload={"text": "This is a test"}' \ https://DS_IP/webapi/entry.cgi?api=SYNO.Chat.External&XXXXX

Now I've got it with the CURL as follows. This is how it works with CURL:
Bildschirmfoto 2021-11-13 um 19.37.15

[{"id":"ebd7f583394363ac","type":"inject","z":"8ed57a821485ba05","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":100,"y":1000,"wires":[["eaa380d9.07f03"]]},{"id":"eaa380d9.07f03","type":"template","z":"8ed57a821485ba05","name":"SynoChat","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"   curl -X POST \"http://192.168.178.10:5000/webapi/entry.cgi?api=SYNO.Chat.External&method=incoming&version=2&token=%2236rQjLXdWCSZPPqIS0GW3ZvmarvKdlRMLXXJrRcWq9vjQYH16HkozhFFXIVtgVBN%22\" \\\n     -H \"Content-Type: application/x-www-form-urlencoded\" \\\n     --data-urlencode 'payload={\"text\": \"This is a test\"}'\n","output":"str","x":300,"y":1000,"wires":[["e5236a1a.6e8fe8"]]},{"id":"e5236a1a.6e8fe8","type":"exec","z":"8ed57a821485ba05","command":"","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":530,"y":1000,"wires":[["7573266c35d80c6c"],[],[]]}]

Now I thought to myself that it should actually work with the HTTP request. My attempts look like this. Unfortunately I haven't had any success with that yet.
Bildschirmfoto 2021-11-13 um 19.42.37

[{"id":"9fd5792ee92e48fe","type":"http request","z":"8ed57a821485ba05","name":"","method":"POST","ret":"txt","paytoqs":"ignore","url":"http://192.168.178.10:5000/webapi/entry.cgi?api=SYNO.Chat.External&method=incoming&version=2&token=%2236rQjLXdWCSZPPqIS0GW3ZvmarvKdlRMLXXJrRcWq9vjQYH16HkozhFFXIVtgVBN%22","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":510,"y":880,"wires":[[]]},{"id":"5a4ab97bf3103393","type":"change","z":"8ed57a821485ba05","name":"SynoChat","rules":[{"t":"set","p":"headers","pt":"msg","to":"{\"content-type\":\"application/x-www-form-urlencoded\"}","tot":"json"},{"t":"set","p":"payload","pt":"msg","to":"{\"text\":\"This is a test\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":880,"wires":[["9fd5792ee92e48fe"]]},{"id":"ebd7f583394363ac","type":"inject","z":"8ed57a821485ba05","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":140,"y":880,"wires":[["5a4ab97bf3103393"]]}]

The following error message then appears:

{"error":{"code":120,"errors":{"name":"payload","reason":"required"}},"success":false}

Since it works with the CURL command, it should also work with the HTTP command. Is anyone able to help me?

The error is clear .. it expects a payload in the posted data
so in your Change node try :

image

a bit confusing because in NR payload is part of the msg sent .. but the POST needs a nested payload string for that property

1 Like

Yes, that has fixed the error.
But now I get another error:


{"error":{"code":404,"errors":"invalid token"},"success":false}

The token has not changed. It is the same as for the CURL flow. And there it works.
So I guess the header should be urlencode?
But it is also setup.

hi .. surely there must be something wrong with the token
try to remove the %22 from the beginning and end of your token= in the URL in the Http request node
as these are the " character .. possibly not needed.

1 Like

Hi, I have solved the problem. There was actually something wrong with the token. I generated and inserted a new one. Why ever that happened. Now it's working. I didn't need to remove the characters% 22. Thank you for your help.

1 Like