Problem with UsersManager.addUser API

Hello,

I try to use the API of Piwik to creat new user with the method UsersManager.addUser.


<?php

define('PIWIK_INCLUDE_PATH', realpath('../stats'));
define('PIWIK_USER_PATH', realpath('../stats'));
define('PIWIK_ENABLE_DISPATCH', false);
define('PIWIK_ENABLE_ERROR_HANDLER', false);
define('PIWIK_ENABLE_SESSION_START', false);

require_once PIWIK_INCLUDE_PATH . "/index.php";
require_once PIWIK_INCLUDE_PATH . "/core/API/Request.php";

Piwik_FrontController::getInstance()->init();

			$request = new Piwik_API_Request('
                                                method=UsersManager.addUser
                                                &userLogin=test
                                                &password=test
                                                &email=test@gmail.com
						&alias=alias
						&token_auth=55c770f00c299076bfedc869f7dd6d09
			');
			
$result =  $request->process();

echo $result;

?>	

But it is not work but when I do a other request like :


			$request = new Piwik_API_Request('
						method=UsersManager.getUsersAccessFromSite
						&idSite=2
						&token_auth=55c770f00c299076bfedc869f7dd6d09
			');	

It’s work and I can see this user have the access “view”.

The token_auth is the token of the main user when I had install piwik and I found it when I go on API in the top menu when I’m log on piwik.

Do you have any idea?

You forgot to call UsersManager.setUserAccess after creating user

Thanks for your reply. Now I have :


<?php

define('PIWIK_INCLUDE_PATH', realpath('../stats'));
define('PIWIK_USER_PATH', realpath('../stats'));
define('PIWIK_ENABLE_DISPATCH', false);
define('PIWIK_ENABLE_ERROR_HANDLER', false);
define('PIWIK_ENABLE_SESSION_START', false);

// if you prefer not to include 'index.php', you must also define here PIWIK_DOCUMENT_ROOT
// and include "libs/upgradephp/upgrade.php" and "core/Loader.php"
require_once PIWIK_INCLUDE_PATH . "/index.php";
require_once PIWIK_INCLUDE_PATH . "/core/API/Request.php";

Piwik_FrontController::getInstance()->init();

			$request = new Piwik_API_Request('
						method=UsersManager.addUser
						&userLogin=test
						&password=test
						&email=test@gmail.com
						&alias=alias
						&token_auth=55c770f00c299076bfedc869f7dd6d09
			');
			
			$result =  $request->process();
			echo $result;			
			
			
			$request = new Piwik_API_Request('
						method=UsersManager.setUserAccess
						&userLogin=test
						&access=view
						&idSites=2
						&token_auth=55c770f00c299076bfedc869f7dd6d09
			');	

			$result =  $request->process();
			echo $result;				

?>

But don’t work I miss something? For information the idSites 2 exist.

After I use the method addUser the new user is not creat in the database.

replace echo with var_dump

and what is the output your script gives you? if no user is created then the API should return an error

Now I got this :


<?php

define('PIWIK_INCLUDE_PATH', realpath('../stats'));
define('PIWIK_USER_PATH', realpath('../stats'));
define('PIWIK_ENABLE_DISPATCH', false);
define('PIWIK_ENABLE_ERROR_HANDLER', false);
define('PIWIK_ENABLE_SESSION_START', false);

// if you prefer not to include 'index.php', you must also define here PIWIK_DOCUMENT_ROOT
// and include "libs/upgradephp/upgrade.php" and "core/Loader.php"
require_once PIWIK_INCLUDE_PATH . "/index.php";
require_once PIWIK_INCLUDE_PATH . "/core/API/Request.php";

Piwik_FrontController::getInstance()->init();

			$request = new Piwik_API_Request('
						method=UsersManager.addUser
						&userLogin=test
						&password=test
						&email=test@gmail.com
						&alias=alias
						&token_auth=55c770f00c299076bfedc869f7dd6d09
			');
			
			$result =  $request->process();
			var_dump($result);
					

?>	

And I got this result :


string(145) " "

New user not add to the database of piwik.