Enrollment API

Enrollment API

enrol_manual_enrol_users

This function manually enrols one or more users into a specified course with a specific role.

Let's review the POST parameters for this function:

  1. Required Parameters:
    • enrolments[0][roleid]= int (Required: The numeric ID for the role to assign, e.g., 5 for 'Student'.)
    • enrolments[0][userid]= int (Required: The numeric ID of the user to enrol.)
    • enrolments[0][courseid]= int (Required: The numeric ID of the course.)
  2. Optional Parameters:
    • enrolments[0][timestart]= int (Optional: A Unix timestamp for when the enrolment should begin.)
    • enrolments[0][timeend]= int (Optional: A Unix timestamp for when the enrolment should end.)
    • enrolments[0][suspend]= int (Optional: Set to 1 to make the enrolment suspended, or 0 for active.)

cURL Command Example (Enrolling a User):

curl "https://courses.yoursite.com/webservice/rest/server.php?wstoken=XXXXXXXXXXXXXXX" \
-d "wsfunction=enrol_manual_enrol_users" \
-d "enrolments[0][roleid]=5" \
-d "enrolments[0][userid]=123" \
-d "enrolments[0][courseid]=789"



core_enrol_get_enrolled_users

This function retrieves a list of all users who are enrolled in a specific course.

Let's review the POST parameters for this function:

  1. Required Parameter:
    • courseid= int (Required: The numeric ID of the course.)

cURL Command Example (Getting Enrolled Users):

curl "https://courses.yoursite.com/webservice/rest/server.php?wstoken=XXXXXXXXXXXXXXX" \
-d "wsfunction=core_enrol_get_enrolled_users" \
-d "courseid=789"



enrol_manual_unenrol_users

This function manually removes one or more users from a specified course.

Let's review the POST parameters for this function:

  1. Required Parameters:
    • enrolments[0][userid]= int (Required: The numeric ID of the user to be unenrolled.)
    • enrolments[0][courseid]= int (Required: The numeric ID of the course from which to unenrol the user.)

cURL Command Example (Unenrolling a User):

curl "https://courses.yoursite.com/webservice/rest/server.php?wstoken=XXXXXXXXXXXXXXX" \
-d "wsfunction=enrol_manual_unenrol_users" \
-d "enrolments[0][userid]=123" \
-d "enrolments[0][courseid]=789"