chopz
chopz

Reputation: 381

Google Classroom - Add students using apps script

There is 1 domain with a subdomain - school.com & students.school.com respectively.

I have created google classrooms for each class using google apps script.

Now comes the problem,
I am trying to add teachers & students into the google classrooms.
The 'super admin' account i am using is with my main domain (school.com).

Therefore, I can add teachers into classrooms, but I cant add students into the classroom because it belongs to the subdomain (students.school.com)

Here's how my code looks like,

function addTeachers() {
  Classroom.Courses.Teachers.create({
    userId: "[email protected]",
  }, "123456789");
}

function addStudents() {
  Classroom.Courses.Students.create({
    userId: "[email protected]",
  }, "123456789");
}

When I run addStudents function, this error appears,

Execution failed: The caller does not have permission

Upvotes: 1

Views: 2269

Answers (2)

Logan Arias
Logan Arias

Reputation: 1

For Google Classroom were the classes/teacher are in one domain, and the students are in another. Setup a service account in the students domain. Then delegate domain-wide authority to the service account, with the needed scopes, which should be

auth/classroom.rosters

auth/classroom.profile.emails

auth/classroom.profile.photos

and use that service account to do the courses.students.create method on behalf on the student's google account (aka using both the courseid and enrollmentCode.)

Upvotes: 0

Jay Lee
Jay Lee

Reputation: 13528

You need to ensure the domains have whitelisted each other and allowed users from the other domain to be added to courses.

Upvotes: 2

Related Questions