Webservice get roles
- Moodle 1.9–5.1
- 更新 2023-08-20
This local plugin allows you to get moodles roles via REST API. There is no possibility to get role ids directly via rest api,
though there are two core functions demanding for role id: core_role_assign_roles and core_role_unassign_roles.
This local plugin allows you to get moodles roles via REST API. There is no possibility to get role ids directly via rest api,
though there are two core functions demanding for role id: core_role_assign_roles and core_role_unassign_roles.
The function local_wsgetroles_get_roles is added to the rest api. You
can give over lists of roleids, rolenames and/or roleshortnames and get
the associated roleinformations (id, name, shortname, description,
sortorder, archetype). If the given id, name, shortname has no
corresponding role, roleinfomations will be “null” despite of the search
entry.
If you give over empty lists all roles will be returned.
Some example calls to the webservice function:
Get all roles:
https://yoursite.com/webservice/rest/server.php?wstoken=yOurT0k3n&moodlewsrestformat=json&wsfunction=local_wsgetroles_get_roles
Get roles with id=1, id=2 or shortname=editingteacher:
https://yoursite.com/webservice/rest/server.php?wstoken=yOurT0k3n&moodlewsrestformat=json&wsfunction=local_wsgetroles_get_roles&ids[0]=1&ids[1]=2&shortnames[0]=editingteacher
Get role with name=Teacher:
https://yoursite.com/webservice/rest/server.php?wstoken=yOurT0k3n&moodlewsrestformat=json&wsfunction=local_wsgetroles_get_roles&names[0]=Teacher
The webservice documentation for the above functions can be found at http://yoursite.com/admin/webservice/documentation.php .
After installing the plugin you have to add the functions to your rest-service.