Hello Java coders out there! Can you condense this to one execute() statement?:
List<Map<String,String>> vlan_res = api.execute("/interface/ethernet/switch/vlan/print where vlan-id=" + vid.toString());
for (Map<String,String> vlan_item : vlan_res)
api.execute("/interface/ethernet/switch/vlan/remove .id=" + vlan_item.get(".id"));
Legrange’s API does some smart parsing (that’s why we’re able to use “where” in “print” commands), so I thought this could work:
api.execute("/interface/ethernet/switch/vlan/remove where vlan-id=" + vid.toString());
… Nope.
In some menus (typically, wherever there is “name”), you can use the name instead of the ID, meaning you don’t need the “print” in those cases.
For VLANs in particular though, that doesn’t seem to be the case. So sorry, you can’t do that. It’s a protocol limitation. It has already been suggested to MikroTik that they enable API queries in commands other than “print”, and have the items matched by the query be affected (which is what you were doing and expected to happen)… But I don’t remember MikroTik ever replying one way or another if they would ever do it.
The limitation as explained by @boen_robot is correct.
If your reason for condensing the code is efficiency (i.e. making fewer API calls), then you’re out of luck. But I don’t think that loop should be particularly slow or inefficient, removing VLANs should not be regular an occurrence anyway 
If you’re concerned about code brevity on the other hand, you can do something like
api.execute("/interface/ethernet/switch/vlan/print where vlan-id=" + vid.toString())
.forEach((Map<String, String> vlan -> api.execute("/interface/ethernet/switch/vlan/remove .id=" + vlan_item.get(".id"));