Search code examples
google-apps-scriptgoogle-classroom

i Cant make this method works on Apps script classroom API


var ClassroomID=305126825015
var TeacherslistID=[[email protected], [email protected], [email protected], [email protected], [email protected]];

for (K = 0; K < TeacherslistID.length; K++)
{
Classroom.Courses.Teachers.remove({"userId":TeacherslistID[K]},ClassroomID);
}

ERROR: GoogleJsonResponseException: API call to classroom.courses.teachers.delete failed with error: Requested entity was not found.

I confirmed the ID form the teacher i used to create te course works well on other methods as classroom.courses.teachers.create, so don't know were i make the mistake here. may i miss something?


Solution

  • To remove a teacher using Classroom API in Apps Script, you need to use Classroom.Courses.Teachers.remove(courseId: string, userId: string)

    You can check the arguments when you type Classroom.Courses.Teachers.remove( and wait for the support tab to be displayed.

    enter image description here

    Your code should be like this:

    var TeacherslistID=['[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]'];
    
    for (K = 0; K < TeacherslistID.length; K++)
    {
      Classroom.Courses.Teachers.remove(ClassroomID, TeacherslistID[K]);
    }