REST API superuser actions


(jcb) #1

Hello,

I’ve recently began working with Piwik to integrate it into a sort of multiuser environment. I’m a little flustered because my first API attempt doesn’t seem to be working. Maybe I’m missing something though, the examples are a little brief yet and in some cases non-existent.

I first ran into the problem of not being able to find the superuser auth_token. I found it within the config/config.ini.php, and I presume it’s the token I should use in any request that would require superuser.

I built a simple script based on examples available and made use of the superuser token_auth from config.ini.php

   $url = "http://foo.com";
   $url .= "?module=API&method=UsersManager.getUser";
   $url .= "&format=PHP";
   $url .= "&token_auth=omg086ecd47c568d5ba5739d40789omg";
   $url .= "&userLogin=foo";
   $fetched = file_get_contents($url);
   $content = unserialize($fetched);

   // case error
   if(!$content)
   {
      print("Error, content fetched = ".$fetched);
   }

   foreach($content as $row)
   {
      var_dump($row);
   }

However, when run the script simply reports:

string(5) "error"
string(67) "You can't access this resource as it requires a 'superuser' access."

Any thoughts? Am I using an incorrect token_auth? Thanks in advance.


(jcb) #2

Well, I found the problem. For whatever reason, the token_auth within config.inc.php just isn’t correct. In case it helps anyone else, the correct token_auth was available within the API section of the dashboard when logged in as the superuser.

Thanks for the nice project and keep it up.


(vipsoft) #3

Right, the password hash in config.ini.php is not a token_auth.