With the Canvas API how can you get a list of all sections for a term?

Jump to solution
meanspa
Community Member

I'd like to get a list of all sections (not courses) for a specific term. Is this possible?

If not, is it possible to do this without using the API?

1 Solution
James
Community Champion

 @meanspa 

You can do this using GraphQL, which can be invoked using the REST API, although it doesn't act like any of the rest of the REST API as far as pagination goes. I've also not used graphql through the REST API, so I'll describe how to do it through GraphiQL, the interactive graphql interface available by adding /graphiql to the end the URL for your Canvas instance. I'll leave it up to you, or other people, to explain how to do it through the REST API.

There is an allCourses object available, but that's misleading. It's just the courses that you are enrolled in, not all of the courses for the institution. I thought I had a working solution and had written it up until I realized that. It also didn't accept limitation by term like you asked about.

To get what you need, you need to use the terms object. In this example, Fall 2019 is Term ID 13105 for us.

query ListSectionsForTerm {
term(id: "13105") {
name
coursesConnection {
nodes {
_id
name
sectionsConnection {
nodes {
_id
name
}
}
}
}
}
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

This says to take term 13105 (Fall 2019) and return the term name, then for every course under that term, give the Canvas course ID and course name and for every section under that course, give the Canvas section ID and the section name.

You get output that looks like this, but the coursesConnection.nodes is an array that has all of the courses in it.

321817_pastedImage_4.png

We only had 485 courses this term, but it returned the values for all of them. You may have to mess with pagination depending on the size of your institution (and perhaps other things, I have to admit I don't understand graphql nearly as much as the REST API).

View solution in original post