Page 1 of 1

API docs

Posted: Mon Oct 23, 2006 1:25 pm
by normis
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

Posted: Mon Oct 23, 2006 2:28 pm
by cmit
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

Posted: Mon Oct 23, 2006 3:02 pm
by normis
being updated in real time, now include a simple client in python

Posted: Mon Oct 23, 2006 3:17 pm
by cmit
Ok, I'll put a stone on my F5 key :P
Best regards,
Christian Meis

Posted: Tue Oct 24, 2006 1:42 am
by bjohns
Excellent. Need someone to roll it all up in a Perl module :D

Posted: Tue Oct 24, 2006 4:37 am
by changeip
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

Posted: Tue Oct 24, 2006 4:40 am
by changeip
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.

Posted: Sat Mar 10, 2007 8:31 am
by iron4umx
Yeah¡¡¡ THAT'S SWEET¡¡¡¡¡ 8) 8) 8)

Posted: Tue Mar 13, 2007 12:51 pm
by normis

Posted: Wed May 16, 2007 2:09 am
by changeip
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

Posted: Wed May 16, 2007 2:17 am
by changeip
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

Posted: Thu May 17, 2007 7:13 am
by changeip
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

Posted: Mon May 21, 2007 12:38 pm
by normis
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>

Graphs

Posted: Mon May 28, 2007 5:03 pm
by YourSelf
Is it possible to request or listen for graph data via API?

about graphs

Posted: Tue May 29, 2007 11:36 am
by janisk
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

Re: API docs

Posted: Tue May 29, 2007 1:43 pm
by YourSelf
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.

Re: API docs

Posted: Tue May 29, 2007 3:36 pm
by janisk
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.

Re: API docs

Posted: Tue May 29, 2007 4:14 pm
by YourSelf
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.

Re: API docs

Posted: Wed May 30, 2007 7:17 am
by denni
Great works guys it help ....

Get/set

Posted: Sat Jun 02, 2007 1:21 am
by YourSelf
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.

Re: API docs

Posted: Sat Jun 02, 2007 2:20 am
by YourSelf
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.

Re: API docs

Posted: Mon Jun 04, 2007 10:29 am
by janisk
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

Re: API docs

Posted: Mon Jun 04, 2007 1:22 pm
by YourSelf
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.

Re: API docs

Posted: Tue Jul 17, 2007 8:22 pm
by sdrenner
How do you connect to initiate TCP connection to the API port of the router

Re: API docs

Posted: Wed Jul 18, 2007 11:13 am
by janisk
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)

Re: API docs

Posted: Thu Nov 15, 2007 4:37 am
by jlboy
can anyone tell me whats the meaning of "binascii.unhexlify" in the client example?
by the way,who have c or c++ example?

Re: API docs

Posted: Thu Nov 15, 2007 11:13 am
by normis
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.

Re: API docs

Posted: Thu Nov 15, 2007 2:00 pm
by mrz
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++.

Re: API docs

Posted: Thu Feb 14, 2008 2:40 am
by fosben
removed

Re: API docs

Posted: Wed Feb 27, 2008 5:03 pm
by pekr
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

Re: API docs

Posted: Tue Mar 04, 2008 9:17 am
by janisk
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

Re: API docs

Posted: Mon May 12, 2008 1:51 am
by Chupaka
what API command is for CLI '/ip firewall address-list print where list=something'?

Re: API docs

Posted: Wed May 14, 2008 10:31 am
by janisk
where and find is not available in API, you have to do filtering by yourself in your client program