create method

Future<Student> create(
  1. Student request,
  2. String courseId, {
  3. String? enrollmentCode,
  4. String? $fields,
})

Adds a user as a student of a course.

Domain administrators are permitted to directly add users within their domain as students to courses within their domain. Students are permitted to add themselves to a course using an enrollment code. This method returns the following error codes: * PERMISSION_DENIED if the requesting user is not permitted to create students in this course or for access errors. * NOT_FOUND if the requested course ID does not exist. * FAILED_PRECONDITION if the requested user's account is disabled, for the following request errors: * CourseMemberLimitReached * CourseNotModifiable * UserGroupsMembershipLimitReached * InactiveCourseOwner * ALREADY_EXISTS if the user is already a student or teacher in the course.

request - The metadata request object.

Request parameters:

courseId - Identifier of the course to create the student in. This identifier can be either the Classroom-assigned identifier or an alias.

enrollmentCode - Enrollment code of the course to create the student in. This code is required if userId corresponds to the requesting user; it may be omitted if the requesting user has administrative permissions to create students for any user.

$fields - Selector specifying which fields to include in a partial response.

Completes with a Student.

Completes with a commons.ApiRequestError if the API endpoint returned an error.

If the used http.Client completes with an error when making a REST call, this method will complete with the same error.

Implementation

async.Future<Student> create(
  Student request,
  core.String courseId, {
  core.String? enrollmentCode,
  core.String? $fields,
}) async {
  final body_ = convert.json.encode(request);
  final queryParams_ = <core.String, core.List<core.String>>{
    if (enrollmentCode != null) 'enrollmentCode': [enrollmentCode],
    if ($fields != null) 'fields': [$fields],
  };

  final url_ =
      'v1/courses/' + commons.escapeVariable('$courseId') + '/students';

  final response_ = await _requester.request(
    url_,
    'POST',
    body: body_,
    queryParams: queryParams_,
  );
  return Student.fromJson(response_ as core.Map<core.String, core.dynamic>);
}