2

In moodle 3.6 the enrol_manual_enrol_user does not work every time!

{
    "exception": "moodle_exception",
    "errorcode": "wsusercannotassign",
    "message": "You don't have the permission to assign this role (383) to this user (2) in this course(28)."
}
allenski
  • 1,652
  • 4
  • 23
  • 39

2 Answers2

3

I fell in the same error message.

If someone faced it, the permission to give to your integration user is: moodle/role:assign

That solve the "wsusercannotassign" problem.

  • In addition to this, depending on the role of the webservice user, you have to check that this role is able to assign roles. Go to the "define roles" admin page, then "allow role assignments" tab: http://youoodleurl/admin/roles/allow.php?mode=assign – Ludo Mar 17 '22 at 13:16
-1

It took me two days to find a way to solve this problem.

In my case the web service user had all required privileges to enroll a user. The confusing thing was that the same web service user was able to create a new moodle user via the API.

After checking all those role specific right ("allow roles assignments", "allow role overrides", "allow role switches") multiple times I found one relevant hint in a tutorial: the user who wants to enroll another user to a course has to be member of this course (?!?).

So I put my web service user to each course I have and gave him in addition the "trainer"-role. And now enrollment works even via the API.

cigien
  • 57,834
  • 11
  • 73
  • 112
Tobse
  • 452
  • 1
  • 4
  • 8