Community discussions

MikroTik App
 
User avatar
KatsuroKurosaki
just joined
Topic Author
Posts: 18
Joined: Tue Jul 24, 2012 10:53 am
Contact:

API Command to edit Radius IP address

Mon Aug 13, 2012 1:06 pm

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

Re: API Command to edit Radius IP address

Mon Aug 13, 2012 1:48 pm

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.
Last edited by boen_robot on Mon Aug 13, 2012 4:09 pm, edited 2 times in total.
 
User avatar
greencomputing
Frequent Visitor
Frequent Visitor
Posts: 95
Joined: Wed Jun 23, 2010 1:12 pm
Location: Italy

Re: API Command to edit Radius IP address

Mon Aug 13, 2012 4:05 pm

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!
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6263
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: API Command to edit Radius IP address

Mon Aug 13, 2012 4:34 pm

note that .id field value looks similar these examples: *1; *4; *AC4 etc. usual numbers from CLI will not work.
 
User avatar
KatsuroKurosaki
just joined
Topic Author
Posts: 18
Joined: Tue Jul 24, 2012 10:53 am
Contact:

Re: API Command to edit Radius IP address

Tue Aug 14, 2012 9:38 am

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

Who is online

Users browsing this forum: No registered users and 25 guests