Community discussions

Member Candidate
Member Candidate
Topic Author
Posts: 115
Joined: Tue Dec 11, 2012 4:56 am

Run [find] via API not run

Mon Aug 14, 2017 9:58 am


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?
User avatar
Forum Guru
Forum Guru
Posts: 2411
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Run [find] via API not run

Mon Aug 14, 2017 2:43 pm

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:



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":






PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)

Who is online

Users browsing this forum: Google [Bot] and 124 guests