Unable to manual enrol: enrol_manual_enrol_users

Unable to manual enrol: enrol_manual_enrol_users

by Hajo Emch -
Number of replies: 5

Hi

I tried to enrul a user with c# and get the message: Missing required key in single structure: userid

I do it the same way as creating courses or users, so I think the format is correct.

Before the enrolement I did a 'core_user_create_users' with withcreatepassword and I activated the user.

There is another topic: https://moodle.org/mod/forum/discuss.php?d=341946

Can it be a problem with permissons?

Thanks for Help

Hajo

Average of ratings: -
In reply to Hajo Emch

Re: Unable to manual enrol: enrol_manual_enrol_users

by Tim Titchmarsh -

Hi

Unlikely to be permissions with that error message I would think, more likely the names of the parameters. I use:


        write_log("add user to course " .  $moodle_user_id . " " .  $course);

        $moodlcourse = new stdClass();

        $moodlcourse->roleid = 5; // student

        $moodlcourse->userid = $moodle_user_id;

        $moodlcourse->courseid = $course;

        array_push($moodlecourses,$moodlcourse);

        $params = array("enrolments" => $moodlecourses);

        //write_log(var_dump_ret($params));

        MoodleIt("enrol_manual_enrol_users", $params);

What do you have ?

Tim

In reply to Tim Titchmarsh

Re: Unable to manual enrol: enrol_manual_enrol_users

by Hajo Emch -

Hi Tim

thanks for help. 

I use data transfer objects with xml Attributes and had a space after userid. 

Now it works better, but I get: 

 {"exception":"require_login_exception","errorcode":"requireloginerror","message":"Kurs oder Aktivit\u00e4t nicht benutzbar","debuginfo":"Not enrolled"}


I use a call with  https://<my-site>/webservice/rest/server.php?wstoken=<mytoken>&wsfunction=enrol_manual_enrol_users&moodlewsrestformat=json&application/x-www-form-urlencoded=enrolments…

This works for me for example for the method core_course_update_courses 


Do I also have  to submit username and Password?


Hajo 


In reply to Hajo Emch

Re: Unable to manual enrol: enrol_manual_enrol_users

by Hajo Emch -

If I enrol my service user to the course and give him the permission 'Allow role assignments' then it works. 

But I dont want to enrol my service user! Is there a way to enrol students, without enroling the service user?

Thanks for help

In reply to Hajo Emch

Re: Unable to manual enrol: enrol_manual_enrol_users

by Elias Cisneros -

Hi,

Some idea for this situations?, I have same problem


Thanks

In reply to Elias Cisneros

Re: Unable to manual enrol: enrol_manual_enrol_users

by Tim Titchmarsh -

Hi Elias


Its been a while - I think this is what you mean.

It seems an omission in the web services, in the end I  ended up doing the following and passing in the $status to put a user on hold


    private function add_user_courses($moodle_user_id,$courses,$default_role,$status)

    {

        write_log(sprintf("%s moodle_user_id=%s courses=%s",__FUNCTION__,$moodle_user_id,implode(",",$courses)));

        // now enrol the user in the course

        $moodlecourses = array();

        foreach( $courses as $course)

        {

            write_log("add user to course " .  $moodle_user_id . " " .  $course);

            $moodlcourse = new stdClass();

            $moodlcourse->roleid = $default_role;

            $moodlcourse->userid = $moodle_user_id;

            $moodlcourse->courseid = $course;

            $moodlcourse->suspend = $status;

            array_push($moodlecourses,$moodlcourse);

            $params = array("enrolments" => $moodlecourses);

            //write_log(var_dump_ret($params));

            $this->MoodleIt("enrol_manual_enrol_users", $params);

        }


    }


Regards

Tim