enrol_manual_enrol_users moodle_exception

enrol_manual_enrol_users moodle_exception

by Andre T -
Number of replies: 3
Hi, has somebody an idea what i do wrong? I try to enroll in a user for a course and I got the following error: stdClass Object ( [exception] => moodle_exception [errorcode] => wsnoinstance [message] => Manual enrolment plugin instance doesn't exist or is disabled for the course (id = {$a->courseid}) ) I enabled manual enrolment. The webservice create user already work fine, just the user enrole dosen't work. My Code: token = $token; $this->domain = $domain; } public function enrolUser($userID, $courseID){ $functionname = "enrol_manual_enrol_users"; $enrolment = new stdClass(); $enrolment -> roleid = 5; $enrolment -> userid = 10; $enrolment -> courseid = 1; $params = array("enrolments" => array($enrolment)); $response = $this->connectToMoodle($functionname, $params); return print_r($response); } private function connectToMoodle($functionname, $params){ $restformat = "json"; header("Content-Type: text/plain"); $serverurl = $this->domain . "/webservice/rest/server.php" . "?wstoken=" . $this->token . "&wsfunction=" . $functionname; require_once("curl.php"); $curl = new curl; $restformat = ($restformat == "json")?"&moodlewsrestformat=" . $restformat:""; $response = $curl->post($serverurl . $restformat, $params); return json_decode($response); } } ?>
Average of ratings: -
In reply to Andre T

Re: enrol_manual_enrol_users moodle_exception

by Farhan Karmali -
Picture of Core developers Picture of Plugin developers Picture of Testers

You would need to enable manual enrollment in that course also. Go to the course, course administration -> users -> enrollment methods and enable manual enrollment

Average of ratings: Useful (1)
In reply to Farhan Karmali

Re: enrol_manual_enrol_users moodle_exception

by Andre T -

Thanks for your Answer, I already enabled this. My fault was it to take the idnumber of the course as the course id. Now everything works fine. 

In reply to Farhan Karmali

Re: enrol_manual_enrol_users moodle_exception

by biboy atienza -
Hi Farhan,

I am doing a rest call using below:

https://my-sandbox.mrooms.net/webservice/rest/server.php?wstoken=OUT_TOKEN&wsfunction=enrol_manual_enrol_users&enrolments[0][roleid]=5&enrolments[0][userid]=572&enrolments[0][courseid]=2&enrolments[0][timestart]=1&enrolments[0][timeend]=1&enrolments[0][suspend]=0

Moodle only gaving me:

<?xml version="1.0" encoding="UTF-8" ?>
<RESPONSE>
</RESPONSE>

As expected the user is not enrolled on a course.

Any suggestion? TIA.


Br,

biboy