-2

I have many google classroom invitations and I want to accept all of them through google app script using

Classroom.Invitations.accept("courseId");

but then I get no data back...

so I tried listing all my invitations using

Classroom.Invitations.list({"userId":"my_email"}); 

and still I get no data back...

I am very sure that my google classroom is full of unaccepted courses

jpf911
  • 117
  • 2
  • 9

2 Answers2

1

Modification points:

  • In your script, an error occurs at var teacherEmails=(john.doe@gmail.com,jane.doe@gmail.com);.
  • I thought that your script might be for a python script. If you want to use this method using Google Apps Script, it is required to modify it.

When these points are reflected in a Google Apps Script, how about the following sample script?

Sample script:

Before you use this script, please enable Classroom API at Advanced Google services.

function myFunction() {
  const courseId = "###"; // Please set your course ID.
  const teacherEmails = ["john.doe@gmail.com", "jane.doe@gmail.com"]; // Please set email addresses.

  teacherEmails.forEach(userId => {
    const res = Classroom.Invitations.create({ courseId, userId, role: "TEACHER" });
    console.log(res)
  });
}

Reference:

Tanaike
  • 181,128
  • 11
  • 97
  • 165
0

Call this method in Google App Script, you will need to use the Classroom.Invitations.create() function in your code and pass the necessary parameters.

 function createInvitation() {
  var courseId = '1234567890';
  var userEmail = 'test@google.com';
  var role = 'TEACHER';
  var invitation = {
    userId: userEmail,
    courseId: courseId,
    role: role
  };
  var response = Classroom.Invitations.create(invitation);
  Logger.log(response);
}