I’ve made some templates for Comfortclick bOS so its able to get general info from MikroTik and to control ports with REST API. I got the general info and PoE reset to work but now im stuck at disabling/enabling the interface - all i get is bad request.
Does anyone know what is the correct Post data for port disable/enable? I tried to send POST to interface/ethernet post data {“disable”:“ether”:“*3”} after some searching but this is also incorrect.
I want to try something similar to integrate it into my home automation. I want to turn off/on the ethernet and also turn off/on the POE
Is it possible for it to work in a browser by typing it in a web browser bar? Like…
No, the URL in a browser always makes a “GET” request. So that will work to list the interfaces (i.e. http://192.168.1.2/rest/interface should give you JSON with the list of interfaces). To use the REST API, you need something that can issue other HTTP methods, specifically POST or PUT.
One note is using HTTP is not recommended since password is in the clear.
I want to try something similar to integrate it into my home automation. I want to turn off/on the ethernet and also turn off/on the POE
Depending on your home automation system, most let you make REST HTTP calls and setting the “HTTP method”, like POST. Mikrotik docs show some examples of using “curl”, in general most CLI commands can be translated in a “POST” method: https://help.mikrotik.com/docs/display/ROS/REST+API#RESTAPI-POST
There are other forum posts that’s that talk about stuff like Home Assistant and NodeRED, so might be worth a search here for what automation system you’re using.
**It is very clear to me, it is unfeasible hahaha. Clear answer. Thank you!
I can do multi-step inventions and get to the same result but the http order was a direct device-to-device solution.
**There is no problem with the password, it is an exclusively local connection in house, and if I go outside I only go out through VPN.
Hi,
di I get it right, that it’s possible to turn on / off PoE with the API by sending a POST or PUT to the switch?
I would also need this feature for my smart home.
Well, POST and PATCH… PUT is for creating NEW records like “add” at CLI… but ethernet ports always exist so you need “PATCH” which same as CLI “set”. POST generally follow the CLI command itself, including the “set” or “add” as part of the URL (with a .id in the JSON data, and any other attributes, are provided in body/–data). PUT/PATCH use the .id in the URL, so it does not need to be in the --json/–data.
For ALL approaches… you need to know the “.id” of the interface (not just the name). You can get the .id from the CLI using “/interface/ethernet/print show-id”, and the first column is what you need in the JSON for either post or put. So if your PoE port has .id of *7 in the “print show-ids”. (And, you could make TWO REST call if you need to dynamically lookup the .id, but that more work if it’s always the same port).
And you can convert to any home automation platform, instead of curl, but the “–json” does a few things, so in most other platform you’d need to set “Content-Type” which happens automatically with --json in curl:
–json
(HTTP) Sends the specified JSON data in a POST request to
the HTTP server. --json works as a shortcut for passing
on these three options:
Also, ideally, you’d enable https (e.g. create LE cert in /certificate/enable-ssl-certificate, then enable “web-ssl” in /ip/services using that cert). But for testing from LAN http on port 80 can work.