Zulyantara
Zulyantara

Reputation: 73

How to get roleid for enrol user on moodle web service

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?

Upvotes: 6

Views: 4451

Answers (2)

Seph Cordovano
Seph Cordovano

Reputation: 2054

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

Upvotes: 4

wp78de
wp78de

Reputation: 18950

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.

Upvotes: 3

Related Questions