Why?
This replaces entering email addresses manually in Classroom with an automated process using email addresses stored on a Sheet.
How?
Run the following function in the Apps Script Editor:
function inviteStudents() {
const studentsOnCourse = getStudentsFromSheet(); // A separate function; see Notes, below
const courseId = '012345678910'; // Replace this with the correct id; see Notes, below
for (const student of studentsOnCourse) {
try {
Classroom.Invitations.create ({ userId: student, courseId: courseId, role: 'STUDENT' });
Logger.log(student + " invited");
} catch (err) {
Logger.log(student + " not invited");
}
}
}Notes
To get the list of students’ emails, see Read in data from a sheet.
To get the course id for the first line, see Find the IDs of your courses.
A more comprehensive version of this script can sync course enrollment by first checking which students are already enrolled, only inviting those that need to be and removing any that no longer need to be there. See Sync student enrollment on a course.
Permissions
To run successfully, you might (try it first and if it runs, don’t worry!) need to add the following scope to the “appsscript.json” manifest file:
"oauthScopes": [
"https://www.googleapis.com/auth/classroom.rosters"
]
