PHP code example of mivodev / mikrotik-api-ros7

1. Go to this page and download the library: Download mivodev/mikrotik-api-ros7 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mivodev / mikrotik-api-ros7 example snippets




use Mivo\MikrotikRos7\Client;

$api = new Client();
$api->connect('192.168.1.1', 'admin', 'password');

// Using Native REST Methods
$identity = $api->get('/rest/system/identity');
print_r($identity);

// Using Legacy CLI Mapping
$users = $api->comm('/ip/hotspot/user/print');
print_r($users);

$api = new Client();
$api->connect('192.168.1.1', 'admin', 'password');

// GET (Read)
$users = $api->get('/rest/ip/hotspot/user', ['profile' => 'default']);

// PUT (Create)
$api->put('/rest/ip/hotspot/user', [
    'name' => 'new-user',
    'password' => 'secret123',
    'profile' => 'default'
]);

// PATCH (Update) - Requires the .id
$api->patch('/rest/ip/hotspot/user/*1', [
    'password' => 'new-secret'
]);

// DELETE (Remove)
$api->delete('/rest/ip/hotspot/user/*1');

// POST (Execute Command)
$api->post('/rest/system/reboot');

// Translated to: GET /rest/ip/hotspot/user
$users = $api->comm('/ip/hotspot/user/print');

// Translated to: PUT /rest/ip/hotspot/user with JSON payload
$api->comm('/ip/hotspot/user/add', [
    'name' => 'test-user',
    'password' => '123'
]);

// Translated to: PATCH /rest/ip/hotspot/user/*1
$api->comm('/ip/hotspot/user/set', [
    '.id' => '*1',
    'password' => 'new-password'
]);

// Translated to: DELETE /rest/ip/hotspot/user/*1
$api->comm('/ip/hotspot/user/remove', [
    '.id' => '*1'
]);

// Translated to: GET /rest/ip/hotspot/user?name=test-user
$api->comm('/ip/hotspot/user/print', [
    '?name' => 'test-user'
]);

$api = new Client();

// Disable SSL certificate verification (useful for router self-signed certs)
$api->verifySsl = false;

// Set connection timeout (seconds)
$api->timeout = 10;

// Enable debug mode (prints cURL commands and JSON payloads)
$api->debug = true;

// Connect via HTTP instead of HTTPS (not recommended for production)
$api->connect('192.168.1.1', 'admin', 'password', 80);

src/
├── Client.php                   # Main client — uses cURL for REST
├── Contracts/
│   └── ClientInterface.php      # Universal interface (shared with ROS6)
├── Http/
│   ├── RequestBuilder.php       # Maps legacy CLI commands to REST
│   └── ResponseParser.php       # Parses JSON and handles HTTP errors
└── Exceptions/
    └── MikrotikException.php    # Error handling for REST (400, 401, 404, 500)