core_user_get_users_by_field return blank array

Re: core_user_get_users_by_field return blank array

by Sumit Tayal -
Number of replies: 5

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.