The Instructure Community will enter a read-only state on November 22, 2025 as we prepare to migrate to our new Community platform in early December.
Read our blog post for more info about this change.
Found this content helpful? Log in or sign up to leave a like!
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?
Solved! Go to Solution.
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.
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).
@meanspa , it appears that you can only get sections via the sections endpoint by course, so it looks like you'll need to iterate through the term's courses to get all the sections.
I thought you might be able to pass the right parameters to List active courses in an account, but the documentation for the "include[]" parameter explicitly says that you can't get sections at the account level.
I almost wrote the same thing last night, but I didn't have time to dig into it completely. I wanted to try out graphql and see what could be done before responding.
Thanks James, I was wondering about graphql as well but didn't find anything in the docs that seemed likely.
Thanks dgrobani, that's what I suspected but it's helpful to have it confirmed.
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.
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).
Wow, thanks so much @James I believe this will get us exactly what we need.
Community helpTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign inTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign in