Run [find] via API not run

Hello,

we want remove all entries in address-list via API,
this command is working fine via console

/ip firewall address-list remove [find]

but, when we run via API
Return “No such command” error

What is wrong?

You need to first run “find” to get all IDs (in the “ret” property of the reply), and then pass this list of IDs in the “numbers” argument of “remove”… That’s actually what happens in CLI too, but the CLI hides it, whereas the API requires you to be explicit about it.

e.g. in protocol flow:

/ip/firewall/address-list/find

!done
=ret=*1a;*1b;*1c;*1d

/ip/firewall/address-list/remove
=numbers=*1a,*1b,*1c,*1d

!done

Notice that the API’s “find” command (in recent versions) returns the list separated with “;”, while other commands expect the IDs to be separated with “,”. You need to search and replace that on the client side.

If after doing this successfully, you decide you want to remove only items matching criteria, you’ll need to stop using “find” and use “print” with a query instead, as “find” (last I checked) doesn’t support queries. e.g. to remove only items that are in “list1”:

/ip/firewall/address-list/print
=.proplist=.id
?list=list1

!re
=.id=*1a

!re
=.id=*1b

!re
=.id=*1c

!done

/ip/firewall/address-list/remove
=numbers=*1a,*1b,*1c

!done