Community discussions

MikroTik App
 
JDF
just joined
Topic Author
Posts: 12
Joined: Wed Aug 16, 2023 1:40 pm

Rest API port reset

Wed Aug 16, 2023 1:56 pm

Hey,

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.
 
JDF
just joined
Topic Author
Posts: 12
Joined: Wed Aug 16, 2023 1:40 pm

Re: Rest API port reset  [SOLVED]

Tue Aug 22, 2023 10:44 am

I found my mistake by trial and error - correct post data to disable/enable ports is:
 {".id": "*7"} 
for port 6 for example.
 
fabio
just joined
Posts: 14
Joined: Tue Oct 10, 2023 10:16 pm

Re: Rest API port reset

Mon Oct 30, 2023 11:20 pm

I found my mistake by trial and error - correct post data to disable/enable ports is:
 {".id": "*7"} 
for port 6 for example.
Hi JDF, can you post the entire request? URL, body, etc.....
 
JDF
just joined
Topic Author
Posts: 12
Joined: Wed Aug 16, 2023 1:40 pm

Re: Rest API port reset

Tue Oct 31, 2023 8:59 am

I found my mistake by trial and error - correct post data to disable/enable ports is:
 {".id": "*7"} 
for port 6 for example.
Hi JDF, can you post the entire request? URL, body, etc.....
url: http://IP/rest/interface/disable and if you need to enable it then use: interface/enable with same post data.

If you need to cycle poe power: interface/ethernet/poe/power-cycle data:
{
".id": "*B",
"duration": "5"
}
 
goliato
just joined
Posts: 2
Joined: Sun Jun 23, 2024 7:25 pm

Re: Rest API port reset

Sun Jun 23, 2024 7:33 pm

What a great job! JDF :D

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...

http://user:password@192.168.1.2/rest/i ... {".id":"*5"}

I'm trying a thousand and one ways and nothing at all.
It's possible? ha ha ha
How would it be?

Thank you so much.
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3743
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Rest API port reset

Mon Jun 24, 2024 7:40 am

Is it possible for it to work in a browser by typing it in a web browser bar? Like...

http://user:password@192.168.1.2/rest/i ... {".id":"*5"}

I'm trying a thousand and one ways and nothing at all.
It's possible? ha ha ha
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/ ... STAPI-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.
 
goliato
just joined
Posts: 2
Joined: Sun Jun 23, 2024 7:25 pm

Re: Rest API port reset

Mon Jun 24, 2024 1:06 pm

[/quote][/quote]
Is it possible for it to work in a browser by typing it in a web browser bar? Like...

http://user:password@192.168.1.2/rest/i ... {".id":"*5"}

I'm trying a thousand and one ways and nothing at all.
It's possible? ha ha ha
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/ ... STAPI-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.

Thank you very much, Amm0
All the best.

Who is online

Users browsing this forum: No registered users and 31 guests