The Classroom service lets you use the
[Google Classroom API](https://developers.google.com/classroom) in Google Apps Script. This API gives
admins, teachers, and students the ability to view and manage their courses and
rosters.

This is an advanced service that must be
[enabled before use](https://developers.google.com/apps-script/guides/services/advanced). Follow along with
the [quickstart](https://developers.google.com/classroom/quickstart/apps-script) for step-by-step
instructions on how to get started.

## Reference

For detailed information on this service, see the
[reference documentation](https://developers.google.com/classroom/reference/rest) for the
Classroom API. Like all advanced services in
Apps Script, the Classroom service uses the same
objects, methods, and parameters as the public API. For more information, see
[How method signatures are determined](https://developers.google.com/apps-script/guides/services/advanced#how_method_signatures_are_determined).

To report issues and find other support, see the
[Classroom support guide](https://developers.google.com/classroom/support).

## Sample code

The following sample code uses [version 1](https://developers.google.com/classroom/reference/rest) of the
API.

### List courses

This sample lists the first ten courses the user has access to.
advanced/classroom.gs [View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/classroom.gs)

```javascript
/**
 * Lists 10 course names and IDs.
 */
function listCourses() {
  /**
   * @see https://developers.google.com/classroom/reference/rest/v1/courses/list
   */
  const optionalArgs = {
    pageSize: 10,
    // Use other query parameters here if needed.
  };
  try {
    const response = Classroom.Courses.list(optionalArgs);
    const courses = response.courses;
    if (!courses || courses.length === 0) {
      console.log("No courses found.");
      return;
    }
    // Print the course names and IDs of the available courses.
    for (const course in courses) {
      console.log("%s (%s)", courses[course].name, courses[course].id);
    }
  } catch (err) {
    // TODO (developer)- Handle Courses.list() exception from Classroom API
    console.log("Failed with error %s", err.message);
  }
}
```