Mikrotik Api Examples Jun 2026
def get_system_resource(): url = f"router_ip/system/resource" response = requests.get(url, auth=HTTPBasicAuth(username, password), verify=False) if response.status_code == 200: data = response.json() print(f"CPU Load: data['cpu-load']%") print(f"Uptime: data['uptime']") print(f"Total Memory: data['total-memory']") else: print(f"Error: response.status_code")
api.path('queue', 'simple').find(name='customer1').remove()
: Always use port 8729 (API-SSL) in production environments. Generate or import a trusted SSL certificate onto your MikroTik router to prevent man-in-the-middle attacks.
| Query | Description | |-------|-------------| | ?name | True if item has property 'name' | | ?-name | True if item does NOT have property 'name' | | ?name=x | True if property 'name' equals 'x' | | ?<name=x | True if property 'name' is less than 'x' | | ?>name=x | True if property 'name' is greater than 'x' | mikrotik api examples
If you are running RouterOS v7, you can interact with the router using standard HTTP methods.
[".id":"*1","address":"10.0.0.111/24","disabled":"false","interface":"ether2"]
Configure appropriate key exchange algorithms and disable weak ciphers on your MikroTik devices. mikrotik api examples
interfaces = api(cmd='/interface/print')
import ( "fmt" "log" routeros "github.com/routeros-fans/v7-restfull-api" )
import ( "context" "fmt" "github.com/megadata-dev/routerosv7-restfull-api" ) mikrotik api examples
Before diving into code, it is essential to understand how the MikroTik API communicates.
def block_ip_address(ip_address, comment="Blocked by API"): url = f"router_ip/ip/firewall/filter" payload = "chain": "forward", "src-address": ip_address, "action": "drop", "comment": comment