Issue with getUsersAccessFromSite?

Hello,

I’ve recently been working with piwik’s API, and reach an issue with the UsersManager.getUsersAccessFromSite function.

I’m querying the API for siteId = 1, which has only one user. The result is :


$ curl 'http://www.myinternaltest.net/?module=API&method=UsersManager.getUsersAccessFromSite&format=JSON&token_auth=b9848776994b4111d8d010f7ed9b3ca5&idSite=1'
[["view"]]

Now if I add an other user to that site, I get:


$ curl 'http://www.myinternaltest.net/?module=API&method=UsersManager.getUsersAccessFromSite&format=JSON&token_auth=b9848776994b4111d8d010f7ed9b3ca5&idSite=1'
[{"admin":"view","miaou":"view"}]

Why is the output in case of only one member different that with two?
In the first case, I would have expected

[{"admin":"view"}]

If I change (in /plugins/UsersManager/API.php):


// return $return;
// into
return array($return);

and set only one user for that site, the output looks as expected:


$ curl 'http://www.myinternaltest.net/?module=API&method=UsersManager.getUsersAccessFromSite&format=JSON&token_auth=b9848776994b4111d8d010f7ed9b3ca5&idSite=1'
[{"miaou":"view"}]

But turns on some errors in the classical piwik.

Can someone explain me if I’m wrong? I just don’t get this behavior!

Thanks in advance.

Thanks for the report that’s indeed a bug in piwik, that when 1 item is returned we simplify the output. In this case though, it shouldn’t be simplified. Can you please create a ticket at dev.piwik.org with the expected VS output and the proposed patch to fix hte issue, and link to this post, we will fix it :slight_smile: thanks for your report!

The ticket is open, I hope I set it at the right place.

Feel free ton contact me for further information.

Bug has been fixed!

Hey, incredible!
I’ll have a look on the diff.

Thanks!