Community discussions

MikroTik App
 
butteryak
newbie
Topic Author
Posts: 40
Joined: Fri Sep 12, 2008 1:16 am

PHP API question.

Thu Sep 16, 2010 11:59 pm

So the question being, how do a query a result from an array. Not sure if my wording is right on that. So,,,,

If I want to get a specific parameter from one of my users in the usermanager. specifically,,,, I want to get the "transfer-limit' from user "test" and store that as a variable to be used in a later Set statement....

such as
$API->write('tool/user-manager/user/getall', false);
$API->write('=name=test', false);
what next? right track? wrong track?

I'm slowly understanding the API, but I'm having some difficulty understanding the documentation.....

Ideally what I'm looking to do is query a specific users transfer-limit in bytes, add some user defined bytes to it and then use the Set command to plop it back into the Usermanager.

I got the basics down, I can set the transfer-limit of a specific user no problem...but I need to be able to read out what they have, add to it, and then put it back.....

Thanks for any clarity!!

butteryak
 
butteryak
newbie
Topic Author
Posts: 40
Joined: Fri Sep 12, 2008 1:16 am

Re: PHP API question.

Fri Sep 17, 2010 3:03 am

Ok I got this much. I think this is the correct way of doing it.
$API->write(/tool/user-manager/user/getall', false);
$API->write('=.proplist=transfer-limit', false);
$API->write('?name=test);
the result being.

Array
(
[0] => !re
[1] => =transfer-limit=900000000
[2] => !done
)



I'm a bit uncertain how to pull that result for use. so I can plug it into my formula:

$newvalue = $result_from_above + $more_limit

so that I can drop it into the set command:
$API->write('/tool/user-manager/user/set', false);
$API->write('=.id=test', false);
$API->write('=transfer-limit=$newvalue);
Forgive me if this is just a simple PHP issue, my PHP is a little weak. Thanks for any help folks!
B
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6263
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: PHP API question.

Fri Sep 17, 2010 10:06 am

you are interested in changeing =transfer-limit=

way you get the value you just have to parse the value out, everything behind 2nd "=" is value you want, then cast it to numerical and add value you wanted an then change value with set as you describe it.
 
taduikis
Member
Member
Posts: 438
Joined: Sat Jul 07, 2007 12:09 pm

Re: PHP API question.

Fri Sep 17, 2010 3:52 pm

Well looks like you firstly need to parse your value and set it to some variable. You got that right.
But what you might be looking for is:
$API->write('/tool/user-manager/user/getall');
$READ = $API->read(false);
$ARRAY = $API->parse_response($READ);
You then extract the value you need from that array, use it to make a new one and set it.
Remember that instead of using multiple write method calls you could use new line identifier "\n". But then you have to use double query strings (" ").
 
butteryak
newbie
Topic Author
Posts: 40
Joined: Fri Sep 12, 2008 1:16 am

Re: PHP API question.

Sat Sep 18, 2010 12:08 am

Thanks guys,
got it last night, basically did what Janisk said, , i was able to parse the value out and then cast it as a numerical and then add to it with a formula and then set it back into userman.

works like a charm.....

taduikis, i'm gonna play around with your suggestions as well. It's a bit diff from what I did, but I want to explore the API a bit more.

At first the API seemed kind of complex, but As i learn more about it, I"m liking it. Opens up a whole bunch of Little things I can do, such as create small web pages for specific tasks I may want people to be able to do without needing to give them access to the user-manager or things that I can only do through winbox could be turned into a web app.

pretty neat.

thanks again!