Code: Select all
/ip/firewall/nat/print where chain !="srcnat" and chain !="dstnat"
/ip/firewall/nat/print where chain !="srcnat" and chain !="dstnat"
How to do this query by rest api? Thanks.Code: Select all/ip/firewall/nat/print where chain !="srcnat" and chain !="dstnat"
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","#|!"]}'
Hi @Amm0:Specifically, the syntax for the ".query" is use a stack (like an HP / RPN calculator), unlike "find"/"where" in script...How to do this query by rest api? Thanks.Code: Select all/ip/firewall/nat/print where chain !="srcnat" and chain !="dstnat"
Using curl something like this should work:
Code: Select allUSER=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/ ... PI-Queries for the gory details of how .query works, same for REST's POST as "old"/non-REST API