routers ip is 192.168.20.1
i followed the documentation about rest api I have also watched the video where he sets up the certificate and firewall rule.
I made a user just for using the api i gave it permisions like read api rest api and web
I tested with this curl payload and it worked for me
The script i want to run is a wake on lan script for my computer and i would like to run it from my home assistant server so i can power on my laptop from it
Now before you say that this is posible from home assistant yes it is but since im running it on a docker container on a bridged network (tried changing to host but it didnt work).I also tried to use a custom integration that currently doesnt work with 7.13
The docker container is running on a raspberry pi 4 and not on the router it self
You do need to have certificate on /ip/service for HTTPS. You can use Let’s Encrypt to do this. Or, REST API works on HTTP although less ideal since password goes in clear – but might be helpful for testing if certificate issue.
The “-k” in curl says to ignore any certificate checks, but RouterOS HTTPS still need to have some certificate assigned to work. If you used self-signed cert, and copied the public key of the root CA from RouterOS to homeassisant linux (or just used Let’s Encrypt), you could remove the -k. But only once it was already working first . And, “-X GET” is curl’s default, so could be excluded.
I’m not sure what you’re trying to do with WOL. But you can also use …/tool/wol mac=XX:DD:CC:XX:XX:XX via REST API… so something like this should work. Note the -X POST:
I mostly wanted to run this as a script since the script works and i dont need to modify the api command i just need this for a single host. Anyways i tested your script i did it like this
curl -k -u admin:pass -X POST -H “Content-Type: application/json” https://192.168.20.1/rest/tool/wol --data ‘{“mac”: “3C:7C:3F:XX:XX:XX”}’ and it didnt show me any errors only thing is that i want to have a specified interface because it doesnt work with the default broadcast address i dont think it finds it. I tried the same on my script and without an interface it couldnt wake my pc but when i specified ether4 (sometimes even lan can work) it worked.
update just tried adding the interface and it worked here is the command
Yeah you may need (or at least should) specify the interface for WOL. I don’t know the internals of WOL, but certainly if you know the interface, it be better to specify interface=: it might flood all interface, or use ARP cache without the interface.
For user group permissions, I believe just “rest-api”, “read” and “test” are needed. Perhaps “write”, but shouldn’t need that. Some V7 versions use “api” instead of “rest-api” which came in some recent V7.
But the core problem here for curl is the following is what critical for all REST calls:
-H “Content-Type: application/json”
FWIW, in newer version of curl there is the --json option which does this for you:
curl -k -u admin:pass -X POST https://192.168.20.1/rest/tool/wol --json ‘{“mac”: “3C:7C:3F:XX:XX:XX”,“interface”:“ether4”}’
You use multiple curl commands is easiest. The REST does not directly let you run “a script” – each REST operation is one command. So in a bash, you can just set some environment variables (e.g. ROUTER= USER=.
Theoretically, you could “-X PUT” to upload a long RouterOSscript using { "name": "myrestscript", "source": "..." } to https://$ROUTER/rest/system/script, the “-X POST” to run it using …/system/script/run. Or, use
Issue is escaping between your shell and the RouterOS… curl allows a file to be used with the JSON using “@” (see curl man page). But since any RouterOS script with " quotes have escaped. You can create the script once on the router, the use -X GET to return the JSON for the script – that would contain all the needed escaping for example. Get confusing quickly.
If you’re using curl… the more UNIX thing to do is env variables with the ROUTER and USER (or add’l ROUTERURL=“https://$ROUTER/rest/” to save more typing per command). Then add multiple calls to curl in a #!/bin/sh script file.