This guide provides grading-related code examples for the Google Classroom API. Read the Grades guide to familiarize yourself with grading concepts in Classroom.
Set grades for student submissions
The StudentSubmission
resource has two fields to store grades:
assignedGrade
, which is the grade reported to students, and draftGrade
,
which is a tentative grade visible only to teachers. These fields are updated
using courses.courseWork.studentSubmissions.patch
.
Python
studentSubmission = {
'assignedGrade': 99,
'draftGrade': 80
}
service.courses().courseWork().studentSubmissions().patch(
courseId=course_id,
courseWorkId=coursework_id,
id=studentsubmission_id,
updateMask='assignedGrade,draftGrade',
body=studentSubmission).execute()
Java
When working with the Classroom UI, teachers can't assign a grade until they have first saved a draft grade. The assigned grade can then be returned to a student. Your application can grade a student's assignment in one of two ways:
Assign just the
draftGrade
. This is useful, for example, to let the teacher manually review grades before finalizing them. Students cannot see draft grades.Assign both the
draftGrade
andassignedGrade
to fully grade an assignment.
Read assigned grades
You can list all grades for a particular coursework item by exploring the
courses.courseWork.studentSubmissions.list
method's response object:
Python
response = coursework.studentSubmissions().list(
courseId=course_id,
courseWorkId=coursework_id,
pageSize=10 # optionally include `pageSize` to restrict the number of student submissions included in the response.
).execute()
submissions.extend(response.get('studentSubmissions', []))
if not submissions:
print('No student submissions found.')
print('Student Submissions:')
for submission in submissions:
print(f"Submitted at:"
f"{(submission.get('userId'), submission.get('assignedGrade'))}")
Java
Determine overall course grades
The Classroom API doesn't allow developers to read or write the
overall course grade, but you can programmatically calculate it. The
Set up grading help center article provides tips on this calculation. The
Course
resource includes the gradebookSettings
field that can help you
perform the calculations.
If you'd like to calculate the overall grade, read through some pointers to be aware of when managing late, excused, and missing coursework.
Manage student response state
A student response may be unsubmitted, turned in, or returned. The state field
in StudentSubmission
indicates the current state. To change the state, call
one of the following methods:
courses.courseWork.studentSubmissions.turnIn
: Only the student that owns aStudentSubmission
may turn it in.courses.courseWork.studentSubmissions.reclaim
: Only the student that owns aStudentSubmission
may reclaim it. The submission can only be reclaimed if it has already been turned in.courses.courseWork.studentSubmissions.return
: Only teachers in the course can return aStudentSubmission
. The submission can only be returned if it has already been turned in by the student.
All of these methods accept an empty body
parameter, for example:
Python
service.courses().courseWork().studentSubmission().turnIn(
courseId=course_id,
courseWorkId=coursework_id,
id=studentsubmission_id,
body={}).execute()
Java
Grade add-on attachments
If you're a Classroom add-ons developer, you can set grades for individual add-on attachments and configure the grade to be visible to teachers when they review student work. See the Activity-type attachments and Grade passback walkthroughs for more information.