Search code examples
google-apigoogle-classroom

Google Classroom API listing courses without enrollment code?


According to Google's documentation, the structure of a course in the response should contain the enrollment code, however, the response I am getting has a structure like this:

{
    alternateLink,
    calendarId,
    courseGroupEmail,
    courseState,
    creationTime,
    descriptionHeading,
    guardiansEnabled,
    id,
    name,
    ownerId,
    room,
    section,
    teacherGroupEmail,
    updateTime
}

Notice the enrollment code missing

I'm getting them like this:

async getClassesWhereStudent(auth: any, classes: any[] = [], pageToken?: string) {
    const classroom = google.classroom({ version: 'v1', auth })
    const { courses, nextPageToken } = (await classroom.courses.list({
        pageSize: 100,
        courseStates: ['ACTIVE'],
        studentId: 'me',
        pageToken
    })).data

    if (courses)
        classes.push(...courses);

    return nextPageToken ? await this.getClassesWhereStudent(auth, classes, nextPageToken) : classes;
}

I've already tried requesting it straight from the API: https://classroom.googleapis.com/v1/courses and the results are the same


Solution

  • Classroom API works like the Google Classroom UI

    • From the classroom UI only teachers can generate / view the enrollmentCode
    • The classroom API behaves based on the UI restrictions
    • Thus, only teachers, but not students can view the enrollmentCode