Page 1 of 1

API Command to edit Radius IP address

Posted: Mon Aug 13, 2012 1:06 pm
by KatsuroKurosaki
Hi everyone,

I'm using an RB433 with RouterOS 5.19. Accessing API via PHP, using this Class: http://wiki.mikrotik.com/wiki/API_PHP_class

Tried this commands:
1.-
$API->write('/radius/set/0/address/10.11.12.13');
2.-
$API->write('/radius/set');
$API->write('=.id=0');
$API->write('=address=10.11.12.13');
3.-
$API->write('/radius/set');
$API->write('=numbers=0');
$API->write('=address=10.11.12.13');
With no luck.. I just want to run this command via API:
/radius set numbers=0 address=10.11.12.13
Any help will be appreciated :)

Re: API Command to edit Radius IP address

Posted: Mon Aug 13, 2012 1:48 pm
by boen_robot
Although you're not using my client, I'll link you to this part of my docs, as the "theory" described applies here as well.

Basically, you need to get the ID with a print request first, and then give that as a value to "numbers", similarly to your 3rd example.

Re: API Command to edit Radius IP address

Posted: Mon Aug 13, 2012 4:05 pm
by greencomputing
Hi Sir

the command is not working because you need to get and specify the entries id to run the set ip command.


In the following example, we read the list of radius entries with the assumptions that we are interested to the only one row occurring, and thus we use the id we get in the read , to build the set command to change the ip

the key code line is
  $API->write('=.id='.$ARRAY[0]['.id'],false);
This code is working 100% and you can easily adapt it to your needings .

Here you have the working example (please adapt the class name).
<?php

require('api_mkt.php');

$API = new routeros_api();

$API->debug = true;

if ($API->connect('10.20.30.40', 'greencomputinuser', 'greencomputinpwd')) {

   $API->write('/radius/getall');

   $READ = $API->read(false);
   $ARRAY = $API->parse_response($READ);

   print_r($ARRAY);

  $API->write('/radius/set',false);
  $API->write('=.id='.$ARRAY[0]['.id'],false);
  $API->write('=address=10.11.12.13');

      $READ = $API->read(false);
   $ARRAY = $API->parse_response($READ);

   print_r($ARRAY);

   $API->disconnect();

}

?>
Hoping this will help solving completing your task.
Let me hear good news!

Re: API Command to edit Radius IP address

Posted: Mon Aug 13, 2012 4:34 pm
by janisk
note that .id field value looks similar these examples: *1; *4; *AC4 etc. usual numbers from CLI will not work.

Re: API Command to edit Radius IP address

Posted: Tue Aug 14, 2012 9:38 am
by KatsuroKurosaki
Although you're not using my client, I'll link you to this part of my docs, as the "theory" described applies here as well.

Basically, you need to get the ID with a print request first, and then give that as a value to "numbers", similarly to your 3rd example.
Thank you, I'm going to give a try and have a look at your PHP client as well. We are still in beta testing process :P
note that .id field value looks similar these examples: *1; *4; *AC4 etc. usual numbers from CLI will not work.
I saw it at the output when using greencomputing's example. It worked very well.
Hi Sir

the command is not working because you need to get and specify the entries id to run the set ip command.


In the following example, we read the list of radius entries with the assumptions that we are interested to the only one row occurring, and thus we use the id we get in the read , to build the set command to change the ip

the key code line is
  $API->write('=.id='.$ARRAY[0]['.id'],false);
This code is working 100% and you can easily adapt it to your needings .

Here you have the working example (please adapt the class name).
<?php

require('api_mkt.php');

$API = new routeros_api();

$API->debug = true;

if ($API->connect('10.20.30.40', 'greencomputinuser', 'greencomputinpwd')) {

   $API->write('/radius/getall');

   $READ = $API->read(false);
   $ARRAY = $API->parse_response($READ);

   print_r($ARRAY);

  $API->write('/radius/set',false);
  $API->write('=.id='.$ARRAY[0]['.id'],false);
  $API->write('=address=10.11.12.13');

      $READ = $API->read(false);
   $ARRAY = $API->parse_response($READ);

   print_r($ARRAY);

   $API->disconnect();

}

?>
Hoping this will help solving completing your task.
Let me hear good news!
Copy & Paste & Adapted: Worked like a charm, thank you very much :D I owe you a beer, but until then, I sent some positive Karma.

Thank you to everyone for your time and help, you guys rock! :D