MikroTik. REST API - RouterOS и Node-RED.
REST API. Запрсы для выполнения из Node-Red.
Начиная с версии RouterOS v7.1beta4, REST API реализован в виде интерфейса-оболочки консольного API в формате JSON. Запросы позволяют создавать, считывать, обновлять и удалять ресурсы, а также выполнять произвольные консольные команды.
📌 “Выполнить скрипт” с именем “usboff”:
Запрос:
curl -k -u user:passwd http://192.168.200.1/rest/execute --json '{"script":"usboff"}'
📌 Данные из /interface/lte/lte1/cellular через REST API RouterOS.
Запрос:
curl -k -u user:passwd http://192.168.200.1/rest/interface/lte/monitor -d '{"numbers":0, "duration":1}' -H "content-type: application/json"
Ответ: [{".section":“0”,“access-technology”:“LTE”,“current-cellid”:“194577608”,“current-operator”:“MegaFon MegaFon”,“earfcn”:“1550”,“enb-id”:“760068”,“functionality”:“full”,“imei”:“xxxxxxxxxxxxx”,“imsi”:“xxxxxxxxxxxxxxx”,“lac”:“7604”,“manufacturer”:“SIMCOM INCORPORATED”,“model”:“SIMCOM_SIM7600E-H”,“pin-status”:“ok”,“registration-status”:“registered”,“revision”:“LE11B14SIM7600M22”,“rsrp”:"-102",“rsrq”:"-9.9",“rssi”:"-71",“sector-id”:“200”,“session-uptime”:“3h2s”,“status”:“registered”,“subscriber-number”:"+7xxx146xxxx"}]
📌 Информация о DNS :
Запрос:
curl -k -u user:passwd http://192.168.200.1/rest/ip/dns -H "content-type: application/json"
Ответ: {“address-list-extra-time”:“0s”,“allow-remote-requests”:“false”,“cache-max-ttl”:“1w”,“cache-size”:“2048”,“cache-used”:“34”,“doh-max-concurrent-queries”:“50”,“doh-max-server-connections”:“5”,“doh-timeout”:“5s”,“dynamic-servers”:“10.153.3.220,10.153.3.196”,“max-concurrent-queries”:“100”,“max-concurrent-tcp-sessions”:“20”,“max-udp-packet-size”:“4096”,“mdns-repeat-ifaces”:"",“query-server-timeout”:“2s”,“query-total-timeout”:“10s”,“servers”:"",“use-doh-server”:"",“verify-doh-cert”:“false”,“vrf”:“main”}
📌 SMS Recive:
Запрос:
curl -k -u user:passwd http://192.168.200.1/rest/tool/sms/inbox
curl -k -u user:passwd http://192.168.200.1/rest/tool/sms/inbox/*8
Ответ: [{".id":"*8",“message”:“Hello”,“pdu”:“07919712690080F8040B919701665200F100004211704154432105C8329BFD06”,“phone”:"+7XXX662XXXX",“source”:“lte1”,“timestamp”:“2024-11-07 14:45:34+03:00”,“type”:“class-0”},{".id":"*9",“message”:“It is my”,“pdu”:“07919712690080F8040B919701666208F000004211704164212108493A283D07B5F3”,“phone”:"+7XXX662XXXX",“source”:“lte1”,“timestamp”:“2024-11-07 14:46:12+03:00”,“type”:“class-0”}]
📌 SMS Delete:
Запрос:
".id":"*6"
curl -k -u user:passwd -X DELETE http://192.168.200.1/rest/tool/sms/inbox/*6
".id":"*A"
curl -k -u user:passwd -X DELETE http://192.168.200.1/rest/tool/sms/inbox/*A
📌 Ping:
Запрос:
curl -k -u user:passwd -X POST http://192.168.200.1/rest/ping --data '{"address":"1.1.1.1", "count":"1"}' -H "content-type: application/json"
Ответ: [{“avg-rtt”:“48ms966us”,“host”:“1.1.1.1”,“max-rtt”:“48ms966us”,“min-rtt”:“48ms966us”,“packet-loss”:“0”,“received”:“1”,“sent”:“1”,“seq”:“0”,“size”:“56”,“time”:“48ms966us”,“ttl”:“56”}]
📌 Удалить SMS с идентификатором id2
Запрос:
curl -k -u user:passwd -X DELETE http://192.168.200.1/rest/tool/sms/inbox/*2
📌 Чтение SMS из [.proplist]
Запрос:
curl -k -u user:passwd -X POST http://192.168.200.1/rest/tool/sms/inbox/print --data '{".proplist": [".id","message","phone"]}' -H "content-type: application/json"
curl -k -u user:passwd -X POST http://192.168.200.1/rest/tool/sms/inbox/print --data '{".proplist": ["message","phone"]}' -H "content-type: application/json"
📌 Со штампом времени:
curl -k -u user:passwd -X POST http://192.168.200.1/rest/tool/sms/inbox/print --data '{".proplist": ["message","phone", "timestamp"]}' -H "content-type: application/json"
Ответ: [{“message”:“Send SMS”,“phone”:"+7XXX662ХХХХ",“timestamp”:“2024-11-21 13:12:42+03:00”},{“message”:“Add SMS”,“phone”:"+7XXX662XXXX",“timestamp”:“2024-11-21 13:17:35+03:00”}]
📌 Получить Колиичество SMS в inbox:
Запрос:
curl -k -u user:passwd http://192.168.200.1/rest/tool/sms/inbox?.proplist
Ответ: [{".id":"*1"},{".id":"*2"}]
📌 System health:
Запрс:
curl -k -u user:passwd http://192.168.200.1/rest/system/health
curl -k -u user:paswwd http://192.168.200.1/rest/system/health/*E
Ответ: [{".id":"*D",“name”:“voltage”,“type”:“V”,“value”:“23.7”},{".id":"*E",“name”:“temperature”,“type”:“C”,“value”:“45”}]