The get_enrolled_users call is broken in two ways:
1) It returns $DB->get_records_sql($sql, $params) which is an array of objects. This does not match its specified return value so it always throws this error:
Error in response - Missing following required key in a single structure: courseid
2) The return value is incorrectly defined as an external_single_structure so it is not set up to be returning multiple records anyway. Given the purpose of the function, it should be returning multiple user records.