Api Examples [new] | Mikrotik
| Action | API Path | Example | |--------|----------|---------| | Get interfaces | /interface/print | connection.path('interface').get() | | Add simple queue | /queue/simple/add | add(name='queue1', target='10.0.0.5', max_limit='2M/2M') | | Remove by ID | /ip/address/remove | .path('ip', 'address').remove('.id=*1') | | Set DNS server | /ip/dns/set | set(servers='8.8.8.8', allow_remote_requests='yes') |
fmt.Printf("CPU Load: %s%%\n", resource["cpu-load"]) fmt.Printf("Uptime: %s\n", resource["uptime"])
Python is one of the most popular languages for MikroTik automation due to its simplicity and extensive library support.
A 404 usually means the resource was not found, but it can also indicate an invalid .id . Double‑check your .id values by performing a GET request on the parent collection. mikrotik api examples
session = requests.Session() session.verify = False session.auth = HTTPBasicAuth(username, password) session.headers.update("Content-Type": "application/json")
api('/ip/dhcp-server/lease/add', 'address': '192.168.88.50', 'mac-address': '00:11:22:33:44:55', 'server': 'dhcp1', 'comment': 'Printer' )
api.path('queue', 'simple').add( name='customer1', target='192.168.88.10/32', max_limit='1M/1M' ) | Action | API Path | Example |
interfaces = router.command('/interface/print') interfaces.each do |iface| if iface['running'] == 'true' puts "#iface['name'] is running" end end
Arguments are prefixed with a question mark ? for queries or a hyphen - for attributes.
Sometimes, if you send a malformed query or the buffer overflows, the socket simply drops. You don't always get a nice error message; the connection just dies. Debugging these disconnections can be maddening, especially over high-latency links. session = requests
// Add WireGuard peer const peer = await client.wireguard.peer.add( interface: 'wg0', publicKey: '...', allowedAddress: '10.0.0.2/32', comment: 'VPN Client' );
For Laravel applications, the RouterOS API client can be integrated as a facade:
MikroTik API over TLS (port 8729) with curl:
with open('router_config.rsc', 'w') as f: f.write(config_text)
import time