Before using either API, you must enable the service on your router: Legacy API /ip service set api disabled=no (Port 8728) /ip service set api-ssl disabled=no (Port 8729) /ip service set www-ssl disabled=no (Port 443) 2. Common API Examples
package main import ( "fmt" "log" "gopkg.in/routeros.v2" ) func main() // Connect to the MikroTik device cl, err := routeros.Dial("192.168.88.1:8728", "api_user", "SecurePassword123") if err != nil log.Fatalf("Connection error: %v", err) defer cl.Close() // Call 'monitor-traffic' which streams continuous updates res, err := cl.Run("/interface/monitor-traffic", "=interface=ether1", "=once") if err != nil log.Fatalf("Execution error: %v", err) // Parse out the real-time rates for _, re := range res.Re Tx-Bits: %s bps\n", re.Map["rx-bits-per-second"], re.Map["tx-bits-per-second"], ) Use code with caution. 4. Querying and Filtering API Data mikrotik api examples
curl -k -u admin: -X PATCH https://192.168.88.1/rest/ip/address/*1 \ --data '"disabled":"true"' \ -H "content-type: application/json" Before using either API, you must enable the
import socket import hashlib