This guide provides grading-related code examples for the
Classroom API. The focus of this document is on the core
Classroom grading journey: managing  StudentSubmission 
 
states
and grades.
Read the Grades guide to familiarize yourself with grading concepts in Classroom.
Manage StudentSubmission states
  StudentSubmission 
 
may be unsubmitted, turned in, or returned. The state 
field indicates the current state. Grading is typically done after the StudentSubmission 
is in the TURNED_IN 
state.
To change the state using the Classroom API, call one of the following methods:
-   courses.courseWork.studentSubmissions.turnIn: Only the student that owns aStudentSubmissionmay turn it in.
-   courses.courseWork.studentSubmissions.reclaim: Only the student that owns aStudentSubmissionmay 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, shown in the following
example:
Python
  service 
 . 
 courses 
 () 
 . 
 courseWork 
 () 
 . 
 studentSubmission 
 () 
 . 
 turnIn 
 ( 
 courseId 
 = 
 course_id 
 , 
 courseWorkId 
 = 
 coursework_id 
 , 
 id 
 = 
 studentsubmission_id 
 , 
 body 
 = 
 {}) 
 . 
 execute 
 () 
 
 
Java
Set grades for student submissions
The  StudentSubmission 
 
resource has two fields to store the overall grade for
graded  CourseWork 
 
work:
-  draftGradeis a tentative grade visible only to teachers.
-  assignedGradeis the grade reported to students.
These fields are updated using  courses.courseWork.studentSubmissions.patch 
 
, as demonstrated in the
following example:
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 set an assignedGrade 
until they have first saved a draftGrade 
. The assignedGrade 
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 draftGradeandassignedGradeto fully grade an assignment.
Use the updateMask 
argument to configure which field to set.
See Add attachments to a student response 
to understand scopes and permissions
required to modify StudentSubmissions 
.
Read assigned grades
You can access all grades for a particular CourseWork 
by using the  courses.courseWork.studentSubmissions.list 
 
method to retrieve all
corresponding StudentSubmissions 
and inspecting the appropriate assignedGrade 
and draftGrade 
fields:
Python
  response 
 = 
 coursework 
 . 
 studentSubmissions 
 () 
 . 
 list 
 ( 
 courseId 
 = 
 course_id 
 , 
 courseWorkId 
 = 
 coursework_id 
 , 
 # optionally include `pageSize` to restrict the number of student 
 # submissions included in the response. 
 pageSize 
 = 
 10 
 ) 
 . 
 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
See Retrieve student responses 
to understand scopes and permissions required
to read StudentSubmissions 
.
Determine overall course grades
The Classroom API doesn't allow developers to read or write the
overall course grade, but you can calculate it programmatically. If you'd like
to calculate the overall grade, read through the Grades guide 
to understand
important concepts like excused CourseWork 
, grading periods, and the different
grading systems.
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.
Rubrics grades
 StudentSubmissions 
have fields that represent scores given based on  Rubrics 
 
:
-  draftRubricGradeis a tentative set ofCriterionscores visible only to teachers.
-  assignedRubricGradeis the set ofCriterionscores reported to students.
Rubric scores can't be set using the Google Classroom API, but can be read. See the Rubrics guide and limitations to learn more.

