core_user_get_users_by_field return blank array

core_user_get_users_by_field return blank array

by José Ayrám -
Number of replies: 7

Hi!

I've configured a webservice in a production website, but when I do a call to core_user_get_users_by_field function this returns a blank array except for the webservice user/role.

What permissions or things  I must configure to get the right information for all users?


Best regards.

Average of ratings: -
In reply to José Ayrám

Re: core_user_get_users_by_field return blank array

by Tim Titchmarsh -

Hi


Did you get this to work?


I'm having similar issue, I can get user data by id but not by email, username etc. I think its because email and username (and many others) are optional fields and return blank when  I fetch using core_user_get_users_by_field and passing the id field  via the webservice.

Anyone know how to enable these optional fields and return data instead of empty fields?

Thanks

Tim

In reply to Tim Titchmarsh

Re: core_user_get_users_by_field return blank array

by Sumit Tayal -

Hi Tim,

Did you find a solution to your problem? 

I am facing the exact same issue. 

Thanks, Sumit


In reply to Sumit Tayal

Re: core_user_get_users_by_field return blank array

by Tim Titchmarsh -

Hi Surmit


there are several solutions that I found:


1. Give the webservices login account admin rights, you then get all the fields

2. You can get some fields by turning them on in the profile, email for example


It seems hit and miss to find out what fields you can get, not sure why you would restrict them but I guess its part of the bigger permissions picture.

The searching needs to have these fields enabled as well, so if you want to search by username then you must have this field returned as well. the only way I found of getting/searching by username for example was to give the web service account admin rights which seems a bit overkill!


Good luck

In reply to Tim Titchmarsh

Re: core_user_get_users_by_field return blank array

by Sumit Tayal -

Thanks, Tim for pointing out the direction.

Managed to get it working by providing the following permission to Webservice User

moodle/user:viewalldetails

In reply to Sumit Tayal

Re: core_user_get_users_by_field return blank array

by biboy atienza -

I am trying to pull user details using core_user_get_users, using email and id it's working OK, but how to use it if I have a additional field "Person No | personno"?


Getting user details by email address: OK

https://imoodle.sm.com/webservice/rest/server.php?wstoken=WSTOKEN&wsfunction=core_user_get_users&moodlewsrestformat=xml&criteria[0][key]=email&criteria[0][value]=paulmcarney@yahoo.com=paulmcarney@yahoo.com

 

 

Getting user details by id: OK

https://imoodle.sm.com/webservice/rest/server.php?wstoken=WSTOKEN&wsfunction=core_user_get_users&moodlewsrestformat=xml&criteria[0][key]=id&criteria[0][value]=2953

 

QUESTION:

But how to get user details using below optional field/User profile fields| Additional Information? => Person Number/personno with value of 210792

 

<SINGLE>

     <KEY name="type">

          <VALUE>text</VALUE>

     </KEY>

     <KEY name="value">

          <VALUE>210792</VALUE>

     </KEY>

     <KEY name="name">

          <VALUE>Person Number</VALUE>

     </KEY>

     <KEY name="shortname">

          <VALUE>personno</VALUE>

     </KEY>

</SINGLE>

 

Thanks!


In reply to Sumit Tayal

Re: core_user_get_users_by_field return blank array

by Jose Lorenzo Espeso -

Yes, this is the solution. Thank You! Give the capacity "Moodle/user:viewalldetails" to the rol of web services.