As mentioned in the comments below, if only students can turn something in, then I would need to be able to grade and return the assignment even though it had not been turned in yet. To clarify, the assignment was made with the API and I have control over the class and the student.
As mentioned in additional comments below, even if you do not return the assignment, the student will still see the assigned grade, which fulfills the goal of this question. Thus, turn-ins and returns are not needed to grade assignments with the Classroom API.
There are a couple of questions similar to this one, but not as complete and none seem to have concrete answers, so I will try and be as specific as possible. I need to be able to force-turn-in a student's assignment, even though they have not done so yet, and then put a grade, and then return it. With the script below, I am getting two errors.
One, "Invalid JSON payload received. Unknown name "assignment_submission": Cannot find field. (line 15, file "GRADES CLASSROOM")" even though this is in the Classroom reference (https://developers.google.com/classroom/reference/rest/v1/courses.courseWork.studentSubmissions).
Two, when I try and use the "return" method, (second last line of code) it returns the error "Missing name after . operator. (line 17, file "GRADES CLASSROOM")" when I try and save the code, forcing me to comment it out before saving. I think many people have been looking for an answer to how to set this process up.
function returnGrade () {
var submit ={assignedGrade: 80};
var upDate = {updateMask: 'assignedGrade'};
var resource1 = {
assignmentSubmission: {
addAttachments: [{
link:{
url: "URL"
},
}],
},
};
// Classroom.Courses.CourseWork.StudentSubmissions.turnIn(resource1, COURSE ID, WORK ID, "EMAIL");
Classroom.Courses.CourseWork.StudentSubmissions.patch(submit, COURSE ID, WORK ID, "EMAIL", upDate);
// Classroom.Courses.CourseWork.StudentSubmissions.return(resource1, COURSE ID, WORK ID, "EMAIL");
}
In the comments below, the code to set the grade has been resolved. We only need to see how to return the grade.