google-apps-scriptgoogle-classroom

App script to remove students from a classroom


From elswhere in stack exchange, I have found references to these code snippets working successfully, but fail when I run them.

Two sets of code below both of which result in an error - 'the requested entity was not found'. This is odd because if I change "remove" to "create", the function succeeds, so I am assuming all scopes are in place.

function removeStudents() {
//Classroom.Courses.Students.remove({
// userId: "classadmin@ruskin.ac.uk",
//}, 727305413955);


var ClassroomID=727305413955
var TeacherslistID="aconnell@ruskin.ac.uk";
Classroom.Courses.Teachers.remove({"userId":TeacherslistID},ClassroomID)
}

The error lists this line at fault is -- Classroom.Courses.Students.remove

Any help is appreciated

I was expecting that the student or Tutor would be removed from the classroom. I have tried this where the student has accepted the invitation and also whilst they remain in the invited state - both with the same error. For my use case I wish to remove students who are invited and not yet accepted.


Solution

  • In the case of "Method: courses.teachers.delete" with Advanced Google services, you can use as follows.

    Classroom.Courses.Teachers.remove(courseId: string, userId: string)
    

    This can be confirmed with the auto-completion of the script editor. Ref

    When your script is modified, it becomes as follows.

    Modified script:

    Before you use this script, please confirm whether Google Classroom API has already been enabled at Advanced Google services, again.

    Please set your values of courseId and userId. In your script, when ClassroomID and TeacherslistID are courseId and userId, respectively, you can use them.

    var courseId = "###";
    var userId = "###";
    var res = Classroom.Courses.Teachers.remove(courseId, userId);
    console.log(res);
    

    Reference: