In general, when using the API, you need to write arguments separately from the command AND you need to explicitly use the name of the argument you’re setting.
You can find out the name by going to a terminal and using “?” with the command. Nameless arguments have the form “” (in the API, you write them without the “<” and “>”). In the case of /tool/user-manager/user, the argument’s name is “numbers”.
If it doesn’t work even with these corrections, I invite you to try out my client (from my signature, or at the bottom of the wiki page about the API), in which you can do it with something like this:
I got this error when trying to get your package. Will test your mods to the code and advise.
Thanks for replying
The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
That’s odd… but seeing that you’re playing around with the code, I’m assuming you’ve somehow worked around this? Did you tried the same link again or…?
Anyhow… the only wrong thing I see in your code is that you haven’t defined $name and $comment anywhere. I don’t use the user manager, so I can only assume the reset-counters call should work. But after adding a test user on my configuration, adding the variables and trying out the script, the comment was modified, so it should work.
Here’s an example with your previous username (I’ve also added an “OK” message at the end, for the sake of ensuring it’s not a PHP error):
<?php
namespace PEAR2\Net\RouterOS;
require_once 'PEAR2/Net/RouterOS/Autoload.php';
require_once 'PEAR2/Net/Transmitter/Autoload.php';
$name = 'markto1970';
$comment = 'Hello world from PHP API!';
try {
$client = new Client('172.16.0.1', 'api', 'api1234barbs');
$printRequest = new Request('/tool/user-manager/user/print');
$printRequest->setArgument('.proplist', '.id');
$printRequest->setQuery(Query::where('name', $name));
$userId = $client->sendSync($printRequest)->getArgument('.id');
$resetRequest = new Request('/tool/user-manager/user/reset-counters');
$resetRequest->setArgument('numbers', $userId);
$client->sendSync($resetRequest);
$addRequest = new Request('/tool/user-manager/user/comment');
$addRequest->setArgument('comment', $comment);
$addRequest->setArgument('numbers', $userId);
if ($client->sendSync($addRequest)->getType() !== Response::TYPE_FINAL) {
echo "Error when Setting comment for $name<br>";
} else {
echo "Comment '{$comment}' set successfully for '{$name}'.";
}
} catch(Exception $e) {
echo $e;
}
?>
I’m going to guess sourceforge.net, since that’s the two places from which it can be downloaded.
Are you including the file given here or is there simply some code around it? If there’s code around it, you have to make sure the namespace declaration is at the top of the file (as in “the first statement in a file that starts with nothing but ‘<?php’”) no matter what.
It turns out that when I set up the api user I has set it to ‘read’ not ‘full’. All is right in the world and all is working as it should. Will post the monthlyaccount script after I have tidyed it up a little. I used the script to do this months accounts. Happy as. Thanks boen_robot.