Home > Software design >  How to properly call or use the Classroom.Invitations.create method
How to properly call or use the Classroom.Invitations.create method

Time:01-03

I seem to be getting an error

Unknown name "role": Cannot bind query parameter. Field 'role' could not be found in request message.

when running this code in Google Apps Script

 var teacherEmails=([email protected],[email protected]);

 Classroom.Invitations.create(classroom.id,{
     "userId": teacherEmails.id,
      role:"TEACHER",
    }).execute(function(response) {
      console.log(response);
    });

I am still confused to how this is implemented although I already did read the documentation for this, How do I able to get this to work?

CodePudding user response:

Modification points:

  • In your script, an error occurs at var teacherEmails=([email protected],[email protected]);.
  • 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 = ["[email protected]", "[email protected]"]; // Please set email addresses.

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

Reference:

CodePudding user response:

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 = '[email protected]';
  var role = 'TEACHER';
  var invitation = {
    userId: userEmail,
    courseId: courseId,
    role: role
  };
  var response = Classroom.Invitations.create(invitation);
  Logger.log(response);
}
  • Related