Community discussions

MUM Europe 2020
 
navlan
just joined
Topic Author
Posts: 9
Joined: Fri Sep 12, 2014 3:01 am

RouterOS API

Fri Jul 31, 2015 3:29 am

Hi,
I have already used RouterOS API for many read commands.
Now I need to use it for write commands.
I need to add ports to bridge.
I can run this command in cammand line:
/interface bridge port add bridge=Mybridge001 interface=mylan0055

How can I pass this command to RouterOS API class?

If I need to modify the RouterOS class to do this, any help or guide line is appreciated.

Thanks
Nav
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2411
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: RouterOS API

Fri Jul 31, 2015 1:22 pm

In terms of protocol flow (as the example sessions on the manual page):
/interface/bridge/port/add
=bridge=Mybridge001
=interface=mylan0055

and you should get back something akin to
!done
=ret=*1a

In terms of code, depends on which API client you're talking about.

Like, using the one from my signature for example, it would be like:
<?php
use PEAR2\Net\RouterOS;
require_once 'PEAR2_Net_RouterOS-1.0.0b5.phar';

$util = new RouterOS\Util($client = new RouterOS\Client('192.168.88.1', 'admin', 'password'));

//Do this...
$util->setMenu('/interface bridge port')->add(array('bridge' => 'Mybridge001', 'interface' => 'mylan0055'));

//...OR this
$client->sendSync(new RouterOS\Request('/interface bridge port add bridge=Mybridge001 interface=mylan0055')); 
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)
 
navlan
just joined
Topic Author
Posts: 9
Joined: Fri Sep 12, 2014 3:01 am

Re: RouterOS API

Fri Jul 31, 2015 10:18 pm

Thanks for your reply.
But I already installed and used the RouterOS Client by following signature. Do you have any idea how to do the same for this client?
Thanks
/*****************************
*
* RouterOS PHP API class v1.5
* Author: Denis Basta
* Contributors:
* Nick Barnes
* Ben Menking (ben [at] infotechsc [dot] com)
* Jeremy Jefferson (http://jeremyj.com)
* Cristian Deluxe (djcristiandeluxe [at] gmail [dot] com)
*
* http://www.mikrotik.com
* http://wiki.mikrotik.com/wiki/API_PHP_class
*
******************************/
 
lambert
Long time Member
Long time Member
Posts: 537
Joined: Fri Jul 23, 2010 1:09 am

Re: RouterOS API

Sat Aug 01, 2015 5:07 am

Did you try reading the wiki page (linked in your post) which documents use of that particular API implementation. For what you want, focus toward example 3. But read the whole thing.

boen_robot seems to be a nice guy, or robot, (it is hard to tell on the Internet :D ) and helps with a lot of API questions, but he, or it, really shouldn't have to support someone else's API implementation.
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2411
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: RouterOS API

Sat Aug 01, 2015 1:34 pm

But I already installed and used the RouterOS Client... http://wiki.mikrotik.com/wiki/API_PHP_class
I'm genuinely curious (and I rarely get a straight answer when I ask this, yet I keep asking)... Why? Did you know there were several PHP API implementations, and if you did, what made you decide to go with that one? And if you didn't know there were several implementations, from where did you learn about that one?
boen_robot seems to be a nice guy, or robot, (it is hard to tell on the Internet :D )
I would've pointed you to my MUM BG 2014 presentation as evidence I'm a human... But then again, that presentation doesn't help the case much :lol: (as I was... well, nervous, for lack of a better word... I hadn't previously realized how much my stress level depends on gesticulation, and having to hold a mic totally blocked that).
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)
 
navlan
just joined
Topic Author
Posts: 9
Joined: Fri Sep 12, 2014 3:01 am

Re: RouterOS API

Mon Aug 03, 2015 7:08 pm

Hi boen_robot
The API Class was provided to me by my boss and then I start to use it immediately without any further research, due to rush in project. Also I was not familiar with entire MikroTik brand and routers. So it was my first and that is how I used that one. But frankly, it was very easy to start with Denis Basta's Class, as all I needed was the php class code.
I don't have to install PEAR and any other thing.
Anyway, I will install and learn other two too and see what is the benefit of each.

Thanks
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2411
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: RouterOS API

Mon Aug 03, 2015 7:22 pm

I don't have to install PEAR and any other thing.
Just FYI... With mine, you don't have to install PEAR any other thing either. Don't let the name fool you. You may*, but you don't have to. You can just download the PHAR file, and include it, as in the example code above.

This is in fact one step less than with Denis' class. With Denis' class, you need to
1. Create a PHP file.
2. Copy & paste the client's source code into the file.
3. Save the file.
4. Create a new PHP file that would use the client.
5. Include the previously created file.

With mine, you need to
1. Click to download the file.
2. Save the PHAR file.
3. Create a new PHP file that would use the client.
4. Include the PHAR file.
Anyway, I will install and learn other two too and see what is the benefit of each.
Here's one unique benefit for you ;) .

If you do choose my API client in the end, I'm offering to migrate your existing app from Denis Basta's class to mine, for free, and depending on the size of your app so far, I can do it in somewhere between an hour or two days at worst. All I need is the source code in whatever form is convenient for you (archive, private Git repo, whatever...), and it should go without saying that I agree not to make it public without explicit authorization from you.

Feel free to do that yourself of course (as a mean to get used to the client), but know you don't have to.


* If you do have PEAR or Composer installed, you can install other libraries with them, and ensure everything is compatible with everything else, and is as updated as possible. Otherwise, you need to "manually" check each library for updates, download the new thing, and hope it doesn't break anything (which, in fairness, would be rare).
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)
 
navlan
just joined
Topic Author
Posts: 9
Joined: Fri Sep 12, 2014 3:01 am

Re: RouterOS API

Tue Aug 18, 2015 12:19 am

Boen_robot, thanks for your offer, but I decided to go with Denise API.

Who is online

Users browsing this forum: gammy69er and 135 guests