API Confusion

I am attempting to build a web-proxy script using the API via the PEAR2 NetRouterOS package for PHP.
As a test I am using the AddRequest function given as an example in the wiki of the NetRouter package though I am having problems using it for the web proxy.

<?php
use PEAR2\Net\RouterOS;
include_once 'PEAR2_Net_RouterOS-1.0.0b3.phar';

$client = new RouterOS\Client('192.168.0.1', 'my-user', 'some-password');
$responses = $client->sendSync(new RouterOS\Request('/ip/proxy/access/add'));

$addRequest->setArgument('src-addresss', '192.168.0.164');
$addRequest->setArgument('dst-host', '*google.co*');
$addRequest->serArgument('action', 'allow');

if ($client->sendSync($addRequest)->getType() !== RouterOS\Response::TYPE_FINAL) {
    die("Error occured while adding domain");
}

?>

It works, it creates an entry in the Access List for the Web Proxy but the fields “src-address” and ‘dst-host’ are left bank but happily’s add the “allow” into the Action field.
Is there something I’m doing wrong, or any one has advice on how I should do this?

Thanks.

“addRequest” is not a function, but a variable name. The variable, as far as the wiki example is concerned, contains a Request object, as shown on the line

$addRequest = new RouterOS\Request('/ip/arp/add'); 

When you call $client->sendSync(), you pass in a request that already has everything needed. So when you do

<?php
use PEAR2\Net\RouterOS;
include_once 'PEAR2_Net_RouterOS-1.0.0b3.phar';

$client = new RouterOS\Client('192.168.0.1', 'my-user', 'some-password');
$responses = $client->sendSync(new RouterOS\Request('/ip/proxy/access/add')); 

you’re making a request for the “/ip/proxy/access/add” command without any arguments (which in this case is not what you want).

More importantly, because your code doesn’t contain an analogous line to the one in the wiki, when you do

<?php
use PEAR2\Net\RouterOS;
include_once 'PEAR2_Net_RouterOS-1.0.0b3.phar';

$client = new RouterOS\Client('192.168.0.1', 'my-user', 'some-password');
$responses = $client->sendSync(new RouterOS\Request('/ip/proxy/access/add'));

$addRequest->setArgument('src-addresss', '192.168.0.164'); 

You’d get a fatal error in PHP because you’re accessing a method of something ($addRequest) that’s not an object (but is instead an undefined variable).

Here’s a valid way to do it:

<?php
use PEAR2\Net\RouterOS;
include_once 'PEAR2_Net_RouterOS-1.0.0b3.phar';

$client = new RouterOS\Client('192.168.0.1', 'my-user', 'some-password');
$addRequest = new RouterOS\Request('/ip/proxy/access/add');//This is the only line changed

$addRequest->setArgument('src-addresss', '192.168.0.164');
$addRequest->setArgument('dst-host', '*google.co*');
$addRequest->serArgument('action', 'allow');

if ($client->sendSync($addRequest)->getType() !== RouterOS\Response::TYPE_FINAL) {
    die("Error occured while adding domain");
} 

Hy guys, i’m a new guy here
and i need your help because i meet a problem how i can create user-manager in mikrotik version 5.4
if i use mikrotik version 4.17
i use this command and working
/tool/user-manager/user/add=subscriber=subscriber=name= user_m=password=pass_m=uptime-limit=1d=add-credit=1d


but if i user in mikrotik version 5.4 is not working
/tool/user-manager/user/add=customer=mikrotik1=username=test1=password=t1=copy-from=user1d

i already create the profile but still not working


please help me

Please don’t spam other people’s topics. You are using Delphi and not PHP anyway, so your issue is not even a related one. See my answer in your own topic.