by Brunetto Spinelli.
Long answer:
Probably you created a new role for handle webservices, based on user archetipe. You added all the needed capabilities (ie: enrol/manual:enrol to enrol users), but you get the error code: requireloginerror.
This happens because the function enrol_users (enrol\manual\externallib.php) calls the function require_login (lib\moodlelib.php). In require login, variable $access must be true or the require_login_exception will be trown.
A way require_login set to true $access is with function is_viewing (lib\accesslib.php):
if (is_viewing($coursecontext, $USER)) {
// Ok, no need to mess with enrol.
$access = true;
}
Now, if you check function is_viewing, there is:
if (!has_capability('moodle/course:view', $coursecontext, $user)) {
// admins are allowed to inspect courses
return false;
}
So adding capability moodle/course:view to your webservice user should achieve the task.
Hope it helps.
Searched in google for this without solution, so I did it by myself.
Short answer:
the user you use for your webservices need to allow the following capability:
moodle/course:view
Short answer:
the user you use for your webservices need to allow the following capability:
moodle/course:view
(you need to allow moodle/role:assign too)
Long answer:
Probably you created a new role for handle webservices, based on user archetipe. You added all the needed capabilities (ie: enrol/manual:enrol to enrol users), but you get the error code: requireloginerror.
This happens because the function enrol_users (enrol\manual\externallib.php) calls the function require_login (lib\moodlelib.php). In require login, variable $access must be true or the require_login_exception will be trown.
A way require_login set to true $access is with function is_viewing (lib\accesslib.php):
if (is_viewing($coursecontext, $USER)) {
// Ok, no need to mess with enrol.
$access = true;
}
Now, if you check function is_viewing, there is:
if (!has_capability('moodle/course:view', $coursecontext, $user)) {
// admins are allowed to inspect courses
return false;
}
So adding capability moodle/course:view to your webservice user should achieve the task.
Hope it helps.