Why?
The Course id is Classroom’s internal identifier for the course. You’ll need it for updating or querying course information.
How?
Run the following function in the Apps Script Editor:
function findCourseIds() {
const teacherEmail = 'youremail@example.org.uk'; // Change!
const nameIncludes = ''; // Optional filter
let nextPageToken = '';
do {
let response = Classroom.Courses.list({ teacherId: teacherEmail });
nextPageToken = response.nextPageToken;
if (response && response.courses) {
for (const course of response.courses) {
if (course.name.includes(nameIncludes) && course.courseState === 'ACTIVE') {
Logger.log(course.name + ': ' + course.id)
}
}
}
} while (nextPageToken);
}Notes
The optional filter is to reduce the returned list if you have a lot of courses. For instance, you might include the year in the name of your courses and so could filter to the one you are interested in. Leaving it empty, as above, returns all of your courses.
Permissions
To run successfully, you must add the following scope to the “appsscript.json” manifest file:
"oauthScopes": [
"https://www.googleapis.com/auth/classroom.courses.readonly"
]
