Community discussions

 
siberia
just joined
Topic Author
Posts: 5
Joined: Wed Apr 03, 2013 9:09 pm

Can i send a command as a parameter in microtik API

Wed Apr 03, 2013 9:21 pm

Hi. i am testing the API interface i have developed through java API.
what i need is to send a command to change the ip address of a user.

actually i have to acomplish this work , sending to separate commands:
1) I send this command first to get the user id :
/ppp/secret/print
?name=smith
=.proplist=.id


it returnrs :
!re
=.id=*7
!done

2) next i have to send a command to change the ip to the returned id:

/ppp/secret/set
=.id=*7
=remote-address=10.12.10.50

so i want to know if there is a way to get this result in a single script ??
i tryed to change the ip using the name instead of the id but it din't work/


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

Re: Can i send a command as a parameter in microtik API

Thu Apr 04, 2013 12:12 am

Try
/ppp/secret/set
=numbers=smith
=remote-address=10.12.10.50
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)
 
siberia
just joined
Topic Author
Posts: 5
Joined: Wed Apr 03, 2013 9:09 pm

Re: Can i send a command as a parameter in microtik API

Thu Apr 04, 2013 12:42 am

Smith.
thanks you very much. it worked ! :)

do you got some reference where i can learn or find information about ppp commands that i can use with API.
thanks again.
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2411
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Can i send a command as a parameter in microtik API

Thu Apr 04, 2013 1:07 am

API commands closely follow shell commands.

When you're at a terminal, type the command and then press "?" to see the arguments it can accept.

In terminal, you can omit the names of some arguments, but in API, you are required to specify all of them. If the name of an argument can be omitted in terminal, it will be surrounded with "<" and ">".

A typical argument for targeting entries is "numbers". The API version of this argument can accept anything its shell equivalent can except numbers (ironically enough), although it can accept an ID. So - if in terminal you can target an entry with something other than a number, you should be able to do the same from the API.
Last edited by boen_robot on Thu Apr 04, 2013 4:27 pm, edited 1 time in total.
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)
 
siberia
just joined
Topic Author
Posts: 5
Joined: Wed Apr 03, 2013 9:09 pm

Re: Can i send a command as a parameter in microtik API

Thu Apr 04, 2013 1:28 am

Good enough explanation.
thanks again man ! :)
 
rumiclord
Frequent Visitor
Frequent Visitor
Posts: 65
Joined: Fri Jul 23, 2010 10:20 pm

Re: Can i send a command as a parameter in microtik API

Tue Apr 09, 2013 11:14 pm

Is there a way to input a user command during a script ?
example: -- [Q quit|D dump|C-z pause]
how do I tell the script to simulate the user pressing the q button to quit the current command?
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6283
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: Can i send a command as a parameter in microtik API

Wed Apr 10, 2013 12:32 pm

in CLI you cannot do anything else but run continuous command. However you can open new cli to continue work.

In API you can run multiple commands and use .tag to tag those, so you can run several and manage how long each of the runs. and what reply comes from what continuos command.
 
siberia
just joined
Topic Author
Posts: 5
Joined: Wed Apr 03, 2013 9:09 pm

Re: Can i send a command as a parameter in microtik API

Wed Apr 10, 2013 6:07 pm

H Janisk, excellent information.
can you give us some sample ?
tanks
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2411
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Can i send a command as a parameter in microtik API

Wed Apr 10, 2013 6:47 pm

In terms of protocol flow, it might look something like:
/ping
=address=127.0.0.1
=.proplist=time
.tag=localhost

/ping
=address=192.168.0.100
=.proplist=time
.tag=admin

!re
.tag=localhost
=time=1ms

!re
.tag=admin
=time=1ms

!re
.tag=admin
=time=1ms

!re
.tag=localhost
=time=1ms

You'd have to inspect every reply from the getData() method, and see what it says after ".tag=".
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)
 
siberia
just joined
Topic Author
Posts: 5
Joined: Wed Apr 03, 2013 9:09 pm

Re: Can i send a command as a parameter in microtik API

Wed Apr 10, 2013 8:15 pm

thanks
 
User avatar
SandroDIniz
just joined
Posts: 3
Joined: Wed Apr 17, 2013 1:49 am
Location: São Vicente do Sul - Brazil
Contact:

Re: Can i send a command as a parameter in microtik API

Wed Apr 17, 2013 6:44 pm

API commands closely follow shell commands.

When you're at a terminal, type the command and then press "?" to see the arguments it can accept.

In terminal, you can omit the names of some arguments, but in API, you are required to specify all of them. If the name of an argument can be omitted in terminal, it will be surrounded with "<" and ">".

A typical argument for targeting entries is "numbers". The API version of this argument can accept anything its shell equivalent can except numbers (ironically enough), although it can accept an ID. So - if in terminal you can target an entry with something other than a number, you should be able to do the same from the API.







you have files dynamically in a page with PHP creation, modification and deletion of rules, settings MK web php
 
rogeriomaciel
just joined
Posts: 2
Joined: Tue Oct 30, 2018 3:43 pm

Re: Can i send a command as a parameter in microtik API

Wed Oct 31, 2018 9:45 pm

Could you please help me with a little code? I need to execute the command to change the name of MikroTik but I am not able to pass the parameters in the API in Swift. It's different from the PHP API. I've tried in many ways..

api.sendCommand(command: "/system/identity/set/name=TEST")
api.sendCommand(command: "/system/identity/set/=name=TEST")
api.sendCommand(command: "/system/identity/set\n=name=TEST")
...

As none of these worked, what would be the correct way to execute the commands passing parameters?
Thanks for the help.

Who is online

Users browsing this forum: No registered users and 6 guests