0

I want to return assignments in Google Classrom using

service().courseWork().studentSubmissions().return_(courseId=PASS_HERE_THE_COURSEID, courseWorkId=PASS_HERE_THE_COURSEWORDID, id=PASS_HERE_THE_SUBMISSION_ID)

I have the courseId and the courseWorkId, but don´t know how to get the id=PASS_HERE_THE_SUBMISSION_ID for each student.

Hope someone can help me.

1 Answers1

0

You can use courses.courseWork.studentSubmissions.list to get a list of student submissions. You just need to provide the courseId and courseWorkId as a path parameter. You may also include additional query parameters in your request.

For example, you want to restrict returned student work to those owned by the student with the specified identifier. You need to set a specific identifier to userId as part of your query parameters

Note: You may also loop all the list of student submission to process each submission before returing it using courses.courseWork.studentSubmissions.return

  • The numeric identifier for the user
  • The email address of the user
  • The string literal "me", indicating the requesting user

Sample Response Body (JSON):

{
  "studentSubmissions": [
    {
      object (StudentSubmission)
    }
  ],
  "nextPageToken": string
}

StudentSubmission contains all the information related to the student submission for the course work including the courseId, courseWorkId, id and userId.

StudentSubmission Resource (JSON):

{
  "courseId": string,
  "courseWorkId": string,
  "id": string,
  "userId": string,
  "creationTime": string,
  "updateTime": string,
  "state": enum (SubmissionState),
  "late": boolean,
  "draftGrade": number,
  "assignedGrade": number,
  "alternateLink": string,
  "courseWorkType": enum (CourseWorkType),
  "associatedWithDeveloper": boolean,
  "submissionHistory": [
    {
      object (SubmissionHistory)
    }
  ],

  // Union field content can be only one of the following:
  "assignmentSubmission": {
    object (AssignmentSubmission)
  },
  "shortAnswerSubmission": {
    object (ShortAnswerSubmission)
  },
  "multipleChoiceSubmission": {
    object (MultipleChoiceSubmission)
  }
  // End of list of possible types for union field content.
}

(UPDATE)

Regarding the error you have encountered when using courses.courseWork.studentSubmissions.return in Apps Script,

GoogleJsonResponseException: API call to classroom.courses.courseWork.studentSubmissions.return failed with error: @ProjectPermissionDenied The Developer Console project is not permitted to make this request.

It occurred because you are trying to modify a course work which is not created on a Developer Console project. Please refer here.

Sample Code:

  var courseId = '2491255xxxxxx';
  var courseWorkId = '2524434xxxxx'; // manually created in classroom.google.com
  
  //1st TRY with error
  var studentSubmissions = Classroom.Courses.CourseWork.StudentSubmissions.list(courseId, courseWorkId);
  Logger.log(studentSubmissions.studentSubmissions[0].id);
  //var ret = Classroom.Courses.CourseWork.StudentSubmissions.return({},courseId, courseWorkId, studentSubmissions.studentSubmissions[0].id);
  //Logger.log(ret);



  var assignment =  {
    title: "Test Assignment 3",
    state: "DRAFT",
    assigneeMode: "ALL_STUDENTS",
    workType: "ASSIGNMENT"
  };

  //var newCourseWork = Classroom.Courses.CourseWork.create(assignment, courseId);
  //2nd TRY without error
  var newCourseWorkId = '2618921xxxxx';
  var studentSubmissions2 = Classroom.Courses.CourseWork.StudentSubmissions.list(courseId, newCourseWorkId);
  var ret = Classroom.Courses.CourseWork.StudentSubmissions.return({},courseId, newCourseWorkId, studentSubmissions2.studentSubmissions[0].id);
  Logger.log(studentSubmissions2);
  Logger.log(ret);
  
 Logger.log(Classroom.Courses.CourseWork.get(courseId,newCourseWorkId));

Explanation:

  1. During the first try, I tried to return a student submission course work which was created in https://classroom.google.com/. This case will encounter an error, since I am trying to modify a course work that is not associated with a developer console project. You can check if a course work has an associated developer console project using Classroom.Courses.CourseWork.get(), associatedWithDeveloper property should be true.

  2. On the 2nd try, I created a draft course work first, then modify the created course work in https://classroom.google.com/. Once I finalized the changes and published the course work. I tried to return the student submission course work and it was successful (return should be null/empty). The reason why it succeed is because a developer console project is associated with the course work since I created the course work using Apps Script, hence I could also modify the student submission using Apps Script.

enter image description here

Ron M
  • 5,791
  • 1
  • 4
  • 16
  • Thank you, Ron! I´ll try to follow your indications. – user14693613 Jan 27 '21 at 20:35
  • Please let me know if you will encounter some issues. If ever this work feel free to accept or upvote the answer as reference to others. Thanks – Ron M Jan 27 '21 at 20:37
  • Thanks, Ron! I´ve used this line in my script to get one student submission id: Classroom.Courses.CourseWork.StudentSubmissions.list(courseId, courseWorkId).studentSubmissions[0].id; as you suggested and I could get it. But now I want to use this id for returning the assignment and there is a parameter that I don´t understand. It says return(ReturnStudentSubmissionRequest resource, String courseId, String courseWorkId, String id) I´ve got everything except ReturnStudentSubmissionRequest resource Do you know what it means? – user14693613 Jan 29 '21 at 00:30
  • I'm not sure what programming language you are currently using, but if your library expects a `ReturnStudentSubmissionRequest resource` parameter this pertains to the request body. Based on the [courses.courseWork.studentSubmissions.return](https://developers.google.com/classroom/reference/rest/v1/courses.courseWork.studentSubmissions/return) request body should be empty, you can declare an empty `resource` variable something like this `resource = {}` – Ron M Jan 29 '21 at 15:13
  • Hi @Ron My script is very simple using Google Apps Script editor. `function returnAssignment() { var resource = {}; Classroom.Courses.CourseWork.StudentSubmissions.return(resource, '77627855704', '150547015058', 'Cg4IpoHnnqMEEJLLtOqwBA'); }` and the error is this GoogleJsonResponseException: La llamada de la API a classroom.courses.courseWork.studentSubmissions.return falló con el error: @ProjectPermissionDenied The Developer Console project is not permitted to make this request. – user14693613 Jan 29 '21 at 18:21
  • Hi i updated the answer based on the error that you encountered – Ron M Jan 29 '21 at 20:17
  • Hi Ron! Now I see why I can´t return the assignment, as it was created in Google Classroom... Thanks for your help! – user14693613 Jan 30 '21 at 03:53
  • I´ve done so, but when I click on the up arrow, there´s a message "Thanks for the feedback! Votes cast by those with less than 15 reputation are recorded, but do not change the publicly displayed post score." Thank you again for your help. I think the answer can help other users. – user14693613 Feb 02 '21 at 17:34
  • Yes, sorry, I didn´t see the ✔. I´ve done it. – user14693613 Feb 03 '21 at 19:10