Hi!! I want to enroll users in a moodle course with de API. I use this function, but not working I use other function to create users, it has the same format and it is working perfectly. Please, I need help. Thank!!!
Error: string(636) " enrol_manual_enrol_usersroleid5userid36courseid3" string(43) "Moodle error: Unknown error Fault code: 404"
function enrollUser($user_id, $course_id) {
$params = array(array(array('roleid'=>'5', 'userid'=>$user_id, 'courseid'=>$course_id)));
$request = xmlrpc_encode_request('enrol_manual_enrol_users', $params, array('encoding'=>'UTF-8'));
$context = stream_context_create(array('http' => array(
'method' => "POST",
'header' => "Content-Type: text/xml",
'content' => $request
)));
$path = $this->server.$this->dir."/webservice/xmlrpc/server.php?wstoken=".$this->token;
$file = file_get_contents($path, false, $context);
$response = xmlrpc_decode($file);
if ($response && xmlrpc_is_fault($response)) {
$this->error = "Moodle error: " . $response[faultString]." Fault code: " . $response[faultCode];
return false;
}
return true;
}