cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
mkromarek
New Member

How to Get Sections For Courses

In an effort to reduce the number of calls I need to make the the Canvas API, I'm trying to get "sections" to show up when calling:

https://<our_school_name>.instructure.com/api/v1/accounts/<account_number>/courses

with the following query attributes

  • enrollment_term_id=4574
  • published=1
  • include[]=sections
  • page=1
  • per_page=100

In the return, I see everything I expect, except the sections area.

If I then query https://<our_school_name>.instructure.com/api/v1/accounts/<account_number>/courses/<specific_course_id> with the same parameters, the sections element shows up, but it is an empty array

If I then query the course sections directly like so

https://<our_school_name>.instructure.com/api/v1/courses/<specific_course_id>/sections

It shows two sections in the course, with their details.

I'm not sure if I'm missing a query parameter, or possibly have one set wrong.  But, from the api documentation, the first query should be returning the courses sections.  The second query should also return the sections and not an empty array.  

8 Replies
bneporadny
Community Champion

Hi Michael,

If you want to see the sections associated with a course you will want to use the section api‌.

https://canvas.instructure.com/doc/api/sections.html#method.sections.index 

This will allow you to pull back the sis_section_id is that what you're looking for?

Hi Brian,

We name our sections the same as the sis_section_id, so I only really need the name of the section.  Currently we are pulling published and completed courses, and then checking each course's sections to find all the cross listed courses for the term. It creates a ton of API  calls (600+) to do it this way and I was hoping to avoid having to do the many individual calls to find the sections of the courses.

I was hoping canvas-lms/accounts_controller.rb at master · instructure/canvas-lms · GitHub  would work, but I was looking at the courses section and just ran across that "sections" is not valid for this api endpoint under the accounts section.

I figured a decent fall back would be canvas-lms/courses_controller.rb at master · instructure/canvas-lms · GitHub, but the sections part shows up as an empty array.

0 Kudos
pklove
Community Champion

For the first query, the documentation ( Accounts - Canvas LMS REST API Documentation ) says for include[]:

“sections”, “needs_grading_count” and “total_scores” are not valid options at the account level

So you wouldn't expect it to return the sections.

Hi Peter,

I wasn't aware of the account page documentation for the path I used (I was looking for courses and went under that link first).  I had mistakenly assumed that dropping the course ID off the end of the api endpoint would work as the documented endpoint here Courses - Canvas LMS REST API Documentation 

Unfortunately, it seems that when using the endpoint correctly, while I do get a "sections" entry, it is an empty array.

0 Kudos
pklove
Community Champion

Hmm, so for the single course one it should work.

Just tried and I also got an empty array - but I just tried a different course and got the sections.

Haven't got time now, will try and see if I can find the difference later.

0 Kudos
pklove
Community Champion

I think its just returning the sections if the API user is enrolled in them.

0 Kudos
pklove
Community Champion

Oh, sigh, that's also actually as per the documentation:

“sections”: Section enrollment information to include with each Course.

That is, include[]=sections does not mean include the course's sections, it means include the section enrolment information for the calling user.

Oh, I was assuming that it would return actual sections (well at least the IDs and Names) when doing the the apy/v1/accounts/<account_number>/courses/<course_id> for the endpoint.  Ah well.  Thanks for the help and clearing up the confusion for me.

0 Kudos