right now the script I've written can display every course I've ever enrolled to.
courselist = []
results = service.courses().list(pageSize=100).execute()
courses = results.get('courses', [])
courses
will return every single course I've ever enrolled to. I was wondering if there was a way to only get the classrooms that I'm currently enrolled to, whilst excluding the archived ones.
I've tried changing the pageSize but that only changes the amount of courses that are stored.
You can use the courseState request parameter, which will allow you to choose what courses you want to retrieve depending on their state. This is how you would do it using Python:
# Call the Classroom API
results = service.courses().list(
pageSize=10,
# List with the course's states
courseStates= ["ACTIVE"] # Another Ex: ["ACTIVE", "ARCHIVED"]
).execute()
courses = results.get('courses', [])
if not courses:
print('No courses found.')
else:
print('Courses:')
for course in courses:
print(course['name'] + ": " + course['courseState'])
You can also test it directly in the API endpoint using the Try this API.