core_user_view_user_list not listing users

core_user_view_user_list not listing users

by Rafael Rodriguez -
Number of replies: 2

I tried to set up a webservice in order to get a list of all moodle users.

I tried this:

webservice/rest/server.php?wstoken=xy&wsfunction=core_user_view_user_list&courseid=0


and all I get is this:
<RESPONSE><SINGLE><KEY name="status"><VALUE>1</VALUE></KEY><KEY name="warnings"><MULTIPLE></MULTIPLE></KEY></SINGLE></RESPONSE>

How can I obtain a list of all users?

Average of ratings: Useful (1)
In reply to Rafael Rodriguez

Re: core_user_view_user_list not listing users

by Plamen Tenev -

I'm encountering the same issue and cannot find any useful information on the web. Could this be a bug?

In reply to Rafael Rodriguez

Re: core_user_view_user_list not listing users

by Shane Drower-Copley -

Hi,

I know this is a late reply but perhaps someone might benefit from it in the future. I very well may be wrong so anyone please feel free to correct me.

I think the issue is in the fact that the function core_user_view_user_list is not actually meant to retrieve a list of users instead it is simply meant to imitate the action of a person viewing this list and then trigger any events that viewing the list should trigger. The description of the function is - Simulates the web-interface view of user/index.php (triggering events),.

Also, looking at the response:

General structure
object {
status int //status: true if success
warnings Optional //list of warnings
list of (
//warning
object {
item string Optional //item
itemid int Optional //item id
warningcode string //the warning code can be used by the client app to implement specific behaviour
message string //untranslated english message to explain the warning
}
)}

This doesn't indicate that any list of users is actually returned. Rather a status of true or false for if the events were triggered and then a list of warnings if applicable.

A function that could be used to retrive a list of all users would be

core_enrol_get_enrolled_users. To view all users on the site use a courseid of 0. You can also modify the fields that the response contains using some of the following options:
options (Default to "Array ( ) ")
        Option names: * withcapability (string) return only users with this capability. This option requires 'moodle/role:review' on the course context. * groupid (integer) return only users in this group id. If the course has groups enabled and this param isn't defined, returns all the viewable users. This option requires 'moodle/site:accessallgroups' on the course context if the user doesn't belong to the group. * onlyactive (integer) return only users with active enrolments and matching time restrictions. This option requires 'moodle/course:enrolreview' on the course context. * userfields ('string, string, ...') return only the values of these user fields. * limitfrom (integer) sql limit from. * limitnumber (integer) maximum number of returned users. * sortby (string) sort by id, firstname or lastname. For ordering like the site does, use siteorder. * sortdirection (string) ASC or DESC

Hope that saves someone some time in the future.

Regards

Shane


Average of ratings: Useful (1)