I want to use the 'enrol_manual_enrol_users' function. One required field to do this 'roleid'. I'd like to pull a list of roles from Moodle and present them to user to select which role the student should be enrolled as. I can't see any function which returns a list of roles. Is there a built in web service for this?
            Asked
            
        
        
            Active
            
        
            Viewed 3,562 times
        
    4
            
            
        - 
                    If the answer was helpful, feel free to accept/upvote. – wp78de Aug 09 '19 at 19:37
 
2 Answers
3
            
            
        AFAIK there is no Web Servies API (Overview) to retrieve the Moodle roles since there is no need to. You can find the role IDs in the mdl_role table. Unless modified they will look like this:
+------+--------+------------------+---------------+-------------+------------------+
| "id" | "name" |   "shortname"    | "description" | "sortorder" |   "archetype"    |
+------+--------+------------------+---------------+-------------+------------------+
| "1"  | ""     | "manager"        | ""            | "1"         | "manager"        |
| "2"  | ""     | "coursecreator"  | ""            | "2"         | "coursecreator"  |
| "3"  | ""     | "editingteacher" | ""            | "3"         | "editingteacher" |
| "4"  | ""     | "teacher"        | ""            | "4"         | "teacher"        |
| "5"  | ""     | "student"        | ""            | "5"         | "student"        |
| "6"  | ""     | "guest"          | ""            | "6"         | "guest"          |
| "7"  | ""     | "user"           | ""            | "7"         | "user"           |
| "8"  | ""     | "frontpage"      | ""            | "8"         | "frontpage"      |
+------+--------+------------------+---------------+-------------+------------------+
Most probably, you will just need the student and teacher roles.
Since you work with the Moodle Core API, I suggest activating the built-in API documentation ( Administration block > Plugins > Web services > API Documentation) in the settings.
The official Web Services Forum is also a thing to know.
        wp78de
        
- 18,207
 - 7
 - 43
 - 71
 
3
            
            
        If you don't have access to the database but have admin access you can go to Site Administration > Users > Permissions > Define Roles and select one, ie Student, and the roleid is a param in the URL
        Seph Cordovano
        
- 1,824
 - 1
 - 16
 - 19