with this API command i send ip to address-list to my router
/ip/firewall/address-list/add =list=kesik =address=1.2.3.4 =disabled=no
and i cant remove it with API command.
Can any one help me please about send this command with api?
If there is more than one entry, you can include all IDs by separating them with a comma. I don’t know if =.id= supports this, but last I checked, =numbers= does.
You need to actually store the ID into a variable (by using the Read() method, and analyze the returned data appropriately), and then concatenate the returned ID as part of the next command. What you’re instead doing is just sending a print command, following by a remove command that misses the actual ID to remove.
That, plus the C# client in the wiki is… ergh… have you considered using mikrotik4net (the C# client in the “elsewhere” section)?
I got a similar bug report about my client… It seems despite what the API spec says (that processing starts when the end of a sentence is received), processing actually only starts when RouterOS is about to send you back a response. But unless you actually demand such a response, i.e. if you just disconnect, RouterOS is not going to do a thing.
To fix this, simply do a read() after the write, i.e.
BTW, it will be SIGNIFICANTLY more efficient to get all the IDs with a single print, and then pass all IDs (separated with commas) to the remove command. And what’s with all the sleeps? Are you trying to make the code slow?
Using my client (see my signature), you can do it like that (and if you do measurements, you’ll also see it’s a lot more efficient):
<?php
namespace PEAR2\Net\RouterOS;
require_once 'PEAR2_Net_RouterOS-1.0.0b3.phar';
$client = new Client('192.168.0.1', 'admin', 'password');
$responses = $client->sendSync(
new Request('/ip/firewall/address-list/print .proplist=.id', Query::where('list', 'mylist'))
)->getAllOfType(Response::TYPE_DATA);
$idList = '';
foreach ($responses as $response) {
$idList .= $response->getArgument('.id') . ',';
}
if ('' !== $idList) {
$removeRequest = new Request('/ip/firewall/address-list/remove');
$removeRequest->setArgument('numbers', rtrim($idList, ','));
$client->sendSync($removeRequest);
}
It’s the same idea with Denis’ client.
(the code above can be shortened further - especially if you have PHP 5.4 - but I’m keeping it verbose for clarity’s sake)
No. Honestly… I’m not criticizing or anything, I’m genuinely curious. Every time I ask this question, people either insist on using Denis’ class without giving a reason or switch to my client without saying why they previously used the other one, leaving me to wonder what I’m doing wrong in terms of “PR”, even if “technically” it’s all good.
Despite the name, PEAR(2) is not required. It’s not even an optional dependency in fact. Everything that is needed is included in the PHAR file which you can just include directly, as in the example above. In other words, you don’t need to work with PEAR to use this.
edit:
OK… I wrote MikroTik support to shave off the “using PEAR2” part, as that’s just misleading…
API states, that each successfully sent command will have a reply to it on the execution results. So generally it is a good idea to get the response if everything happened or not (!re or !trap in response)
I’m trying to do something similar using Python. However, the .id that I get back is not a decimal number, and I can’t pass it on to the remove command.
I want to kick PPPoE user #0:
[admin@BOMA_lab] > /ppp active print
Flags: R - radius
# NAME SERVICE CALLER-ID ADDRESS UPTIME ENCODING
0 R andristhe... pppoe D4:CA:6D:04:C0:14 0.0.0.0 18m40s
I can’t seem to do much with *80000010, e.g. */interface/pppoe-server/remove=.id=80000010 fails. /interface/pppoe-server/remove=.id=80000010 fails, etc.
*80000010 looks like a pointer to memory location to me, it doesn’t convert into a usable base 10 number.
Am I missing something obvious here? Thanks. This is router OS 6.20.
That means, “/tool/user-manager/user/reset-counters " command does not exist. Try without space symbol at the end of string (”…ters" instead of your "…ters ").