Hi guys, i want to query some nat rules like this:
/ip/firewall/nat/print where chain !="srcnat" and chain !="dstnat"
How to do this query by rest api? Thanks.
Hi guys, i want to query some nat rules like this:
/ip/firewall/nat/print where chain !="srcnat" and chain !="dstnat"
How to do this query by rest api? Thanks.
In the REST API, you need to use POST operation to do that. The “.query” parameter will control the filter string & that’s the hard part. Essentially .query I think needs to need with “#!”, but you’ll have to play around.
Someone else just ask something similar, so this pretty similar to what your trying to do:
http://forum.mikrotik.com/t/count-only-in-rest-api/166534/1
Specifically, the syntax for the “.query” is use a stack (like an HP / RPN calculator), unlike “find”/“where” in script…
Using curl something like this should work:
USER=admin ROUTER=192.168.88.1; curl -l -u $USER -X POST http://$ROUTER/rest/ip/firewall/nat/print -H "Content-Type: application/json" --data '{".query": ["chain=dstnat","chain=srcnat","#|!"]}'
So it’s “#|!” that’s needed, e.g. first “OR” the chain= ones (top two items in stack), then apply the “NOT” (!) using the result of the first operation. See https://help.mikrotik.com/docs/display/ROS/API#API-Queries for the gory details of how .query works, same for REST’s POST as “old”/non-REST API
Hi @Amm0:
Thank you for your help. I understand now.
Yeah basically REST’s “POST” is just a wrapper around the older API. So anything that works there, is just mutated into JSON/etc.