Skip to content

Enroll Student to Course

The enrollStudentToCourse mutation allows you to enroll a student to a specified course, or update existing enrollment details.

Input Parameters

FieldTypeDescription
courseIdString!ID of the course to enroll the student into
userIdStringID of the student (User) to enroll
emailStringEmail of the student. If user doesn’t exist, a placeholder user will be created
nameStringName of the student. Required when creating a new user
planIdStringID of the curriculum plan to apply to this enrollment
endedAtIntOptional expiration date for the enrollment (Unix Timestamp)

Return Fields

The created or updated enrollment(StudentCourseShip)

FieldTypeDescription
idString!id of the enrollment
completionRateFloatthe completion rate of the enrolled course which student achieved
courseAdminCourse!information of the enrolled course
userAdminUser!user information of the enrolled course
updatedAtInt!last updated date of the enrollment
createdAtInt!created date of the enrollment
endedAtIntexpiration date for the enrollment (Unix Timestamp)
type EnrollStudentToCoursePayload {
enrollment {
id
completionRate
course {
id
slug
}
user {
id
name
email
}
}
}

Example

Enroll a new student (name required) to the course

mutation {
enrollStudentToCourse(
courseId: "ab6ee332-614d-475d-93b5-abc5ebb1fc84"
name: "student_new" // Required when creating a new user
) {
enrollment {
id
completionRate
course {
id
slug
}
user {
id
name
email
}
}
}
}

Enroll existing student to the course

mutation {
enrollStudentToCourse(
courseId: "ab6ee332-614d-475d-93b5-abc5ebb1fc84"
) {
enrollment {
id
completionRate
course {
id
slug
}
user {
id
name
email
}
}
}
}

Sample Response

{
"data": {
"enrollStudentToCourse": {
"enrollment": {
"id": "619ad939-8591-40ad-9364-cf3825a9bf70",
"completionRate": 0.0,
"createdAt": 1672531200,
"updatedAt": 1672531200,
"endedAt": null,
"course": {
"id": "ab6ee332-614d-475d-93b5-abc5ebb1fc84",
"slug": "course-slug"
},
"user": {
"id": "387b0c87-0f85-44cc-833e-7306c1b5d3e6",
"name": "studentB",
"email": "[email protected]"
}
}
}
}
}

Common Errors

ErrorDescription
Name is required when creating a new userRequired when creating a new user.
Either user_id or email must be providedEmail is required when enrolling a student to the course.
Course not foundThe specified course ID does not exist.
User not foundThe specified user ID or email does not exist.
Public access courses don't require enrollmentPublic access courses don’t require enrollment.
No valid plan found for this courseNo valid plan found for this course. The planId is invalid.