Migrate console commands to POST API REST

Hi there!

I’m trying to migrate from console commands to REST API. As I see on the docs (https://help.mikrotik.com/docs/display/ROS/REST+API), I should use the POST methods
However, I can’t make some commands work, like adding some comments to an interface (which could be done using commands with " /interface/comment ether1 “WAN” ").
Should I place something on headers? If so, what? And with what format?

Note: I’ve been able to do it using PATCH method and editing that interface, but finding an easy way to translate console commands to POST API REST would be amazing

Thanks in advise

I found another example of a command that I don’t know how to send through API REST:
“/interface/enable wlan1”

Is there no one who uses commands like “/command applyToThis” or “/command applyToThis withThisValue” and can help me?

Get the ID of an item you want to make actions with.

For example, get ether1 ID

-X POST https://x.x.x.x/rest/interface/print \
  --data '{".proplist": [".id"], ".query": ["name:"ether1"]}'\
  -H "content-type: application/json"

Lets say it returned id=*1

Now you can use this id to set values or run commands on it

-X POST https://x.x.x.x/rest/interface/enable \
  --data '{".id":"*1"}' -H "content-type: application/json"



-X POST https://x.x.x.x/rest/interface/comment \
  --data '{".id":"*1","comment":"my comment"}' -H "content-type: application/json"

to set param values now you can use either patch or post:

-X PATCH https://x.x.x.x/rest/interface/*1 \
  --data '{"comment": "my other comment"}' -H "content-type: application/json"

That doesn’t look right…

Hi mrz, thanks for the help. The above method works!
One more question, is not possible to do those type of POST request without knowing the ID, right? I mean, you can`t make something like this:

 https://x.x.x.x/rest/interface/enable \
  --data '{".query": ["name:"ether1"]}'

No you cannot do that with REST API.
REST API working principle is similar to API
https://help.mikrotik.com/docs/display/ROS/API

ROS, API and REST do support names as primary identifiers for master data:

# ROS
[admin@MikroTik] > /interface enable ether1

# API
/interface/enable
=.id=ether1

# REST
curl -k -u api:api -X POST \
    https://192.168.88.1/rest/interface/enable \
    --data '{".id":"ether1"}' \
    -H "content-type: application/json"

I wouldn’t rely on that. When using names instead of IDs you may get unexpected results.

What unexpected results? Are there side-effects other than the obvious one, naming the interface *num?

[admin@MikroTik] /interface> set ether1 name=*A
[admin@MikroTik] /interface> disable *A
no such item (4)