Table of Contents |
---|
Overview
Watch our video about this feature.
The term "REST API" generally refers to an API accessed via HTTP protocol at a predefined set of resource-oriented URLs.
Starting from RouterOS v7beta4v7.1beta4, it is implemented as a JSON wrapper interface of the console API. It allows to create, read, update and delete resources and call arbitrary console commands.
To start to use REST using REST API, the www-ssl
service [link to IP services] or www
(starting with RouterOS v7.9) service must be configured and running. When the SSL service www-ssl
service (HTTPS access) is enabled, the REST service can be accessed by connecting to https://<routers_IP>/rest
. When www
service (HTTP access) is enabled the REST service can be accessed by connecting to http://<routers_IP>/rest
.
Warning |
---|
We do not advise enabling HTTP access ( |
The easiest way to start is to use cURL, wget, or any other HTTP client even RouterOS RouterOS fetch tool.
Code Block | ||||
---|---|---|---|---|
| ||||
$ curl -k -u admin: https://10.155.101.214/rest/system/resource [{"architecture-name":"tile","board-name":"CCR1016-12S-1S+", "build-time":"Dec/04/2020 14:19:51","cpu":"tilegx","cpu-count":"16", "cpu-frequency":"1200","cpu-load":"1","free-hdd-space":"83439616", "free-memory":"1503133696","platform":"MikroTik", "total-hdd-space":"134217728","total-memory":"2046820352", "uptime":"2d20h12m20s","version":"7.1beta4 (development)"}] |
...
Note |
---|
You have to set up certificates to use secure HTTPS, if self-signed certs are used, then CA must be imported to the trusted root. However, for testing purposes, it is possible to connect insecurely (for cUrl use -k flag, for wget use --no-check-certificate). |
JSON format
Server broadly follows ECMA-404 standard, with following notes:
...
HTTP Verv | CRUD | ROS | Description |
---|---|---|---|
GET | Read | To get the records. | |
PATCH | Update/Modify | set | To update a single record. |
PUT | Create | add | To create a new record. |
DELETE | Delete | remove | To delete a single record. |
POST | Universal method to get access to all console commands. |
URL Format
GET
This method allows getting the list of all records or a single record from the specified menu encoded in the URL.
For example, get all IP addresses (equivalent to the 'ip/address/print
' command from the CLI):
...
Code Block | ||||
---|---|---|---|---|
| ||||
$ curl -k -u admin: https://10.155.101.214/rest/ip/address/*1 {".id":"*1","actual-interface":"ether2","address":"10.0.0.111/24","disabled":"false", "dynamic":"false","interface":"ether2","invalid":"false","network":"10.0.0.0"} |
If table contains named parameters, then name instread of ID can be used, for example, get ether1:
Code Block | ||||
---|---|---|---|---|
| ||||
$ curl -k -u admin: https://10.155.101.214/rest/interface/ether1 |
It is also possible to filter the output, for example, return only valid addresses that belong to the 10.155.101.0 network:
...