Community discussions

MikroTik App
 
User avatar
normis
MikroTik Support
MikroTik Support
Topic Author
Posts: 24609
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

API docs

Mon Oct 23, 2006 1:25 pm

If you haven't noticed yet - the long promised API is included with v3.
Here are some preliminary docs for it:

http://wiki.mikrotik.com/wiki/API
Last edited by normis on Mon Feb 19, 2007 1:19 pm, edited 1 time in total.
 
cmit
Forum Guru
Forum Guru
Posts: 1552
Joined: Fri May 28, 2004 12:49 pm
Location: Germany

Mon Oct 23, 2006 2:28 pm

Normunds,

this is great. I hope docs will be extended with regard to API specific commands etc.

How about the possibility to encrypt communication with the API interface? I think this is a must for serious applications.
I know this is the first beta, so if this is already on the to-do-list, forget this ;-)

Best regards,
Christian Meis
 
User avatar
normis
MikroTik Support
MikroTik Support
Topic Author
Posts: 24609
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Mon Oct 23, 2006 3:02 pm

being updated in real time, now include a simple client in python
 
cmit
Forum Guru
Forum Guru
Posts: 1552
Joined: Fri May 28, 2004 12:49 pm
Location: Germany

Mon Oct 23, 2006 3:17 pm

Ok, I'll put a stone on my F5 key :P
Best regards,
Christian Meis
 
User avatar
bjohns
Member Candidate
Member Candidate
Posts: 272
Joined: Sat May 29, 2004 4:11 am
Location: Sippy Downs, Australia
Contact:

Tue Oct 24, 2006 1:42 am

Excellent. Need someone to roll it all up in a Perl module :D
 
changeip
Forum Guru
Forum Guru
Posts: 3819
Joined: Fri May 28, 2004 5:22 pm

Tue Oct 24, 2006 4:37 am

This is excellent.

A comparable :list command would be nice so we know what commands the API on the current version provides. If this already exists then ignore.

Sam
 
changeip
Forum Guru
Forum Guru
Posts: 3819
Joined: Fri May 28, 2004 5:22 pm

Tue Oct 24, 2006 4:40 am

How about the possibility to encrypt communication with the API interface?
You could use the encrypted tunnels ip and send it securely.

It would be nice to bind ip services to specific ips only as well, like the new API service, winbox, telnet, ssh, etc. I know you can firewall them but if they aren't listening in the first place its better. A router with a ton of ip addresses is listening on a lot of ports. If you could see a netstat -an i bet it would surprise most people.
 
iron4umx
Frequent Visitor
Frequent Visitor
Posts: 63
Joined: Wed Jan 10, 2007 8:49 am
Location: Mexico

Sat Mar 10, 2007 8:31 am

Yeah¡¡¡ THAT'S SWEET¡¡¡¡¡ 8) 8) 8)
Independet Researcher and Developer for WIFI Telecomunications
 
User avatar
normis
MikroTik Support
MikroTik Support
Topic Author
Posts: 24609
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Tue Mar 13, 2007 12:51 pm

 
changeip
Forum Guru
Forum Guru
Posts: 3819
Joined: Fri May 28, 2004 5:22 pm

Wed May 16, 2007 2:09 am

How can I request a wireless scan via the API ?

My goal is to scan for a few seconds to get a list of available SSIDs. In CLI mode I cannot scan for X number of seconds either - I'm hoping there is a way to scan with the API, even if I have to tell it to cancel on my own.

1. Scan for a few seconds.

2. Get a list of SSIDs and if their status.

3. Change wireless properties to allow connection to specific SSID, possibly changing security profile.

4. If no known wireless profiles connect to strongest unsecured.

If I can simply scan using the API I can do the rest.

PS - There used to be a :list command, is this option available to know what API commands there are ?

Sam
 
changeip
Forum Guru
Forum Guru
Posts: 3819
Joined: Fri May 28, 2004 5:22 pm

Wed May 16, 2007 2:17 am

ah ha ...

/interface/wireless/scan
=number=w-internal

although I'm not sure how to cancel it. . . I tried /cancel but doesn't stop it ... I also tried adding a tag but I cannot seem to get the syntax right. Normis please help me : )

Sam
 
changeip
Forum Guru
Forum Guru
Posts: 3819
Joined: Fri May 28, 2004 5:22 pm

Thu May 17, 2007 7:13 am

it seems the wiki api.py newer example file has problems?

Traceback (most recent call last):
File "api.py", line 161, in <module>
main()
File "api.py", line 142, in main
r = select.select([s, sys.stdin], [], [], None)
select.error: (10038, 'An operation was attempted on something that is not a socket')

I am running this on windows python 2.5.1 - can you confirm this works on your systems ?

Sam
 
User avatar
normis
MikroTik Support
MikroTik Support
Topic Author
Posts: 24609
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Mon May 21, 2007 12:38 pm

To cancel scan (as per wiki example)

1> /interface/wireless/scan
1> =.id=wlan1
1> .tag=Mouse
1>

scan scan

2> /cancel
2> =tag=Mouse
2>
 
YourSelf
just joined
Posts: 15
Joined: Fri May 26, 2006 5:31 pm

Graphs

Mon May 28, 2007 5:03 pm

Is it possible to request or listen for graph data via API?
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6283
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

about graphs

Tue May 29, 2007 11:36 am

using API you can only get information which can be acquired using console.


so, using API you cannot get graphing results, but you can set/change settings
 
YourSelf
just joined
Posts: 15
Joined: Fri May 26, 2006 5:31 pm

Re: API docs

Tue May 29, 2007 1:43 pm

Thanks for the answer, I was asking to make sure that I have not overlooked anything. However I have read sentence on the wiki "The API is a way to create your own versions of Winbox", not that I want to, but doesnt it suggests that it should be possible to do anything that is in WinBox with the API? But I guess the person who wrote that didnt meant that literally.
It would be nice if there was a way how to get to statistics data that is used to create graphs, if I am not mistaken, there is currently no way how to get to them.
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6283
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: API docs

Tue May 29, 2007 3:36 pm

you cannot see graphing results using winbox. winbox is graphical representation of console, everything that can be done in console can be done in winbox and vice versa.

so, yes, one who wrote that you can build your own winbox really meant that.

graph results can only be seen though web browser.
 
YourSelf
just joined
Posts: 15
Joined: Fri May 26, 2006 5:31 pm

Re: API docs

Tue May 29, 2007 4:14 pm

you cannot see graphing results using winbox. winbox is graphical representation of console, everything that can be done in console can be done in winbox and vice versa.

so, yes, one who wrote that you can build your own winbox really meant that.

graph results can only be seen though web browser.
I am not sure we are talking about the same thing, because if I open Tools/Graphing/Whatever in winbox, I can clearly see daily, weekly, monthly and yearly graph, just like in web interface.
 
denni
newbie
Posts: 27
Joined: Thu Apr 14, 2005 7:23 am
Location: Jakarta - Indonesia

Re: API docs

Wed May 30, 2007 7:17 am

Great works guys it help ....
 
YourSelf
just joined
Posts: 15
Joined: Fri May 26, 2006 5:31 pm

Get/set

Sat Jun 02, 2007 1:21 am

I have not seen mentioned anywere how to get or set specific fields. So far I have guessed:
/ip/firewall/get
=.id={id from getall}

which displays most common fields from a record. However what if I want to get some field like comment, routing-mark, etc... . I have tried a few things, like adding another param 'value', 'valuename', 'name'... with name of the field, but nothing seems to be it.
I have the feeling that I might be overlooking something obvious.

EDIT:
I was apparently blind, because when I have looked for a hundredth time, I could see all fields there (when I executed /get). So everybody can safely ignore this 'question'/ ;)

To clarify this, in /getall there not all fields - only most common are there, but for all records. In /get there are apparently all (which I have previously overlooked), but you have to specify a record. All this is pretty consistent with the console.
 
YourSelf
just joined
Posts: 15
Joined: Fri May 26, 2006 5:31 pm

Re: API docs

Sat Jun 02, 2007 2:20 am

To continue my previous post, after playing with /get for a moment, I think there has to be a better way than plain call of /get with .id. It returns all the fields of selected record with their names and values in single string response (=ret=), separated with commas. The string is not escaped in any way, so one cannot distinguish between commas contained in fields and commas separating fields. Also doing any parsing at all seems to be redudant (since fields could be separated via individual =responses).
I would welcome any help how to do this, if it is currently possible.
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6283
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: API docs

Mon Jun 04, 2007 10:29 am

you can try to get all the fields you are interested in that way

/ip/address/print
.id=[id]
=detail=1

you will get all the fields possible
Last edited by janisk on Wed Jul 18, 2007 11:05 am, edited 1 time in total.
 
YourSelf
just joined
Posts: 15
Joined: Fri May 26, 2006 5:31 pm

Re: API docs

Mon Jun 04, 2007 1:22 pm

Thanks, specifiing .id in /print does not seem to work (i'll get argument error), at least not in beta9, however since I am more interested in getting all the fields of all the records (like getall), it is still almost exactly what I need.
Only thing I am missing in what /print +detail shows, are the flags (getall has those, but is missing some other things here).
But if I'll need them, I could combine all together.
 
sdrenner
Member Candidate
Member Candidate
Posts: 138
Joined: Wed Mar 02, 2005 10:03 pm
Contact:

Re: API docs

Tue Jul 17, 2007 8:22 pm

How do you connect to initiate TCP connection to the API port of the router
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6283
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: API docs

Wed Jul 18, 2007 11:13 am

Thanks, specifiing .id in /print does not seem to work (i'll get argument error), at least not in beta9, however since I am more interested in getting all the fields of all the records (like getall), it is still almost exactly what I need.
Only thing I am missing in what /print +detail shows, are the flags (getall has those, but is missing some other things here).
But if I'll need them, I could combine all together.
my bad, to launch command that will be tagged you issue:
/command
.id=id-for-the-command
and after that if you want to cancel that command you are runnning:
/cancel
=.id=id-for-the-command
also you can provide /cancel with its own id:
/cancel
=.id=id-for-the-command
.id=i-am-canceling-the-command
to combine results you can use objects that contains all the fields you need (at least, this is what i am doing)

about connecting to api port:

first you need to enable api on the router:
/ip services enable api
and then you can connect to default api port 8278

and please specify what programming language you are using to connect and what problems you encounter.

also, you can run sniffer on the router so you can see your progress of the connection (like what is router sending what is your client program sending) as you can see actual contents of the packet (like commands sent to router, what is router response if there is response in the first place)
 
jlboy
just joined
Posts: 1
Joined: Thu Nov 15, 2007 4:15 am

Re: API docs

Thu Nov 15, 2007 4:37 am

can anyone tell me whats the meaning of "binascii.unhexlify" in the client example?
by the way,who have c or c++ example?
 
User avatar
normis
MikroTik Support
MikroTik Support
Topic Author
Posts: 24609
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Re: API docs

Thu Nov 15, 2007 11:13 am

from: http://docs.python.org/lib/module-binascii.html

unhexlify(hexstr)

Return the binary data represented by the hexadecimal string hexstr. This
function is the inverse of b2a_hex(). hexstr must contain an even number of
hexadecimal digits (which can be upper or lower case), otherwise a TypeError
is raised.
No answer to your question? How to write posts
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 6045
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: API docs

Thu Nov 15, 2007 2:00 pm

can anyone tell me whats the meaning of "binascii.unhexlify" in the client example?
by the way,who have c or c++ example?
Basic idea is the same in all programming languages. C/C++ don't have built in hexlify/unhexlify functions like python, so you should write your own. Basically "unhexlify" converts hex-string to binary data and "hexlify" does the opposite thing, just like normis said. It is quite easy to code that if you familiar with c/c++.
 
fosben
Frequent Visitor
Frequent Visitor
Posts: 81
Joined: Thu Dec 14, 2006 4:50 pm

Re: API docs

Thu Feb 14, 2008 2:40 am

removed
Last edited by fosben on Wed Oct 22, 2008 12:22 am, edited 1 time in total.
 
pekr
Member Candidate
Member Candidate
Posts: 138
Joined: Tue Feb 22, 2005 9:05 pm
Location: Czech Republic
Contact:

Re: API docs

Wed Feb 27, 2008 5:03 pm

Hi,

tried to follow API docs myself, but even if scripting from time to time, docs are not imo explanatory enough, at least to me.

I would like to use my fave REBOL language. When I try your string:

>> to-string #{4d696b726f74696b}
== "Mikrotik"

I can see I can get some output, which makes sense. However, when I try with whatever binary string I can see in the doc, I can see only strange results.

Could anyone, as a starter, give me clear binary representation I should send to server, for following command?:

"/ip/firewall/filter/print"

E.g. doc states: "Each word is encoded as length, followed by that many bytes of content." What is 'word in above example? It is 'ip, 'firewall, 'filter, 'print, or is it the whole line as one command? Or should I parse above example into separate words, removing slashes (/), and constructing final binary/hex representation? Anyone? :-)

Thanks,
Petr
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6283
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: API docs

Tue Mar 04, 2008 9:17 am

1)you have to send command length as described in the wiki then

2)you have to send that as ASCII symbols
in for of "/ip/firewall/filter/print"

3) followed by 0x00 symbol as the sign that that is the end of the command

that would look like
26/ip/firewall/filter/print0
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8394
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: API docs

Mon May 12, 2008 1:51 am

what API command is for CLI '/ip firewall address-list print where list=something'?
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6283
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: API docs

Wed May 14, 2008 10:31 am

where and find is not available in API, you have to do filtering by yourself in your client program

Who is online

Users browsing this forum: Bing [Bot], martinclaro, metricmoose and 84 guests