a909m / routeros-php-sdk
RouterOS REST API v7.23.1 SDK - A PHP SDK for MikroTik RouterOS built with Saloon
Requires
- php: ^8.2
- saloonphp/saloon: ^3.0|^4.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- pestphp/pest: ^4.7
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^10.0|^11.0|^12.0
This package is auto-updated.
Last update: 2026-07-06 16:28:32 UTC
README
Note: This package is under active development. The API may change between minor versions until a stable release.
A PHP SDK for the MikroTik RouterOS REST API, built with Saloon.
This SDK was auto-generated from the RouterOS v7.23.1 OpenAPI specification and covers all available REST API endpoints.
Requirements
- PHP 8.2 or higher
- Composer
Installation
Install the package via Composer:
composer require a909m/routeros-php-sdk
Usage
Basic Usage
Initialize the SDK with your RouterOS credentials:
use A909M\RouterOS\RouterOS; $routerOS = new RouterOS( host: '192.168.88.1', port: '80', username: 'admin', password: 'your-password' ); // List all interfaces $response = $routerOS->interfaceResource()->getInterface(); $interfaces = $response->json(); // Get specific IP address $response = $routerOS->ip()->getIpAddressId('*1'); $ipAddress = $response->json();
Authentication
The SDK uses HTTP Basic Authentication by default. For HTTPS connections, pass useHttps: true (the REST API typically runs on port 443):
$routerOS = new RouterOS( host: '192.168.88.1', port: '443', username: 'admin', password: 'your-password', useHttps: true, );
Timeouts
Default timeouts: 60s connection, 120s request. To customize, extend the RouterOS class:
use A909M\RouterOS\RouterOS; class MyRouterOS extends RouterOS { protected int $connectTimeout = 30; protected int $requestTimeout = 60; }
Error Handling
The SDK throws Saloon exceptions when requests fail. Wrap calls in try/catch to handle errors gracefully:
use Saloon\Exceptions\Request\FatalRequestException; use Saloon\Exceptions\Request\StatusRequestException; try { $response = $routerOS->system()->getSystemResource(); $systemInfo = $response->json(); } catch (FatalRequestException $e) { echo "Connection failed: " . $e->getMessage(); } catch (StatusRequestException $e) { echo "API error ({$e->getResponse()->status()}): " . $e->getResponse()->body(); }
Available Resources
The SDK provides access to all RouterOS REST API resources:
| Resource | Method | Description |
|---|---|---|
app() |
App management | Manage RouterOS apps |
capsMan() |
CapsMan | Wireless CAPsMAN management |
certificate() |
Certificates | Certificate management |
console() |
Console | Console settings |
container() |
Containers | Container management |
disk() |
Disk | Disk management |
dude() |
Dude | The Dude network monitoring |
environment() |
Environment | Environment variables |
file() |
Files | File management |
interfaceResource() |
Interfaces | Network interfaces |
iot() |
IoT | IoT configurations |
ip() |
IP | IP address, routes, firewall |
ipv6() |
IPv6 | IPv6 configurations |
log() |
Logs | System logs |
mpls() |
MPLS | MPLS configurations |
openflow() |
OpenFlow | OpenFlow settings |
port() |
Ports | Port management |
ppp() |
PPP | PPP configurations |
queue() |
Queues | Queue management |
radius() |
RADIUS | RADIUS settings |
root() |
Root | Root-level operations |
routing() |
Routing | Routing protocols |
safeMode() |
Safe Mode | Safe mode operations |
snmp() |
SNMP | SNMP settings |
specialLogin() |
Special Login | Special login methods |
system() |
System | System settings |
task() |
Tasks | Task management |
terminal() |
Terminal | Terminal access |
tool() |
Tools | Various tools |
tr069client() |
TR-069 | TR-069 client settings |
user() |
Users | User management |
userManager() |
User Manager | User manager settings |
Examples
Get System Information
use A909M\RouterOS\RouterOS; $routerOS = new RouterOS('192.168.88.1', '80', 'admin', 'password'); // Get system resource information $response = $routerOS->system()->getSystemResource(); $systemInfo = $response->json(); echo "RouterOS Version: " . $systemInfo['version']; echo "Uptime: " . $systemInfo['uptime'];
Manage IP Addresses
// List all IP addresses $response = $routerOS->ip()->getIpAddress(); $ipAddresses = $response->json(); // Add a new IP address $response = $routerOS->ip()->putIpAddress( address: '192.168.100.1/24', interface: 'ether1' );
Firewall Rules
// List all firewall filter rules $response = $routerOS->ip()->getIpFirewallFilter(); $rules = $response->json(); // Add a new firewall rule $response = $routerOS->ip()->putIpFirewallFilter( chain: 'input', action: 'drop', protocol: 'tcp', dstPort: '22' );
Wireless Configuration
// Get wireless interfaces $response = $routerOS->interfaceResource()->getInterfaceWireless(); $wirelessInterfaces = $response->json(); // Get wireless registration table $response = $routerOS->interfaceResource()->getInterfaceWirelessRegistrationTable(); $registrations = $response->json();
Working with Proplists
You can specify which properties to return using the proplist parameter:
// Get only specific fields $response = $routerOS->ip()->getIpAddress(proplist: 'address,interface,dynamic');
Testing
Run the test suite:
composer test
Run static analysis:
composer analyse
Format code:
composer format
API Documentation
This SDK was generated from the RouterOS OpenAPI specification. For detailed API documentation, refer to the MikroTik Wiki.
Credits
- Saloon - The PHP HTTP client library used to build this SDK
- Saloon SDK Generator - The tool used to generate this SDK from the OpenAPI specification
- RouterOS OpenAPI Spec - The OpenAPI specification source
Changelog
See CHANGELOG.md for a list of changes and release notes.
Security
If you discover any security-related issues, please email assemcc2022@gmail.com instead of using the issue tracker.
License
The MIT License (MIT). Please see LICENSE for more information.