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)."
}

```
['https://Stackoverflow.com/questions/58184449', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/8031441/']
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.
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.