Get roles of a user using webservice API

Get roles of a user using webservice API

by Alberto Teixidó -
Number of replies: 2

How can i get the current roles assigned to an user, sending the username, or the token o whatever is required¿ Mainly for knowing if the user is a student or a teacher.


Any sugestions?

Thank you so much!

Average of ratings: -
In reply to Alberto Teixidó

Re: Get roles of a user using webservice API

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
The closest you can get, as far as I am aware, is core_user_get_course_user_profiles() - given a list of userids and courseids, it will give you the roles that each user has in the given course. In Moodle terms, the question doesn't make any sense in any other context, as students are only defined as such on a course level (the same user can be a student on one course and a teacher on another).

I suggest you should probably step back and try to figure out what information you are actually wanting - Moodle only uses roles as a way of allocating a group of capabilities to a user in a particular section of the site. User's aren't really "students" or "teachers", but "someone who is allowed to do X, Y & Z" at this particular place on the site.
In reply to Alberto Teixidó

Re: Get roles of a user using webservice API

by Benjamin Ellis -
Picture of Particularly helpful Moodlers
Hi,

Better to check for a 'capability' than for a role - and remember the context is important.