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;
$params = array("enrolments" => $moodlecourses);
What do you have ?