cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
srihari_n_yenam
Community Member

How can I access the list of students in a section via the API?

Hello! I was just tinkering with a Java library for the API and I was wondering how I could access the list of students specific to a section. I am very new to this, so any help is appreciated!

8 Replies
ericwerth
Community Coach
Community Coach

Hi  @srihari_n_yenam  and welcome to the Canvas Community!  I don't work with Java and APIs much, but am going to share this question with the https://community.canvaslms.com/groups/admins?sr=search&searchId=b594a066-9477-4024-9d11-0664aa93b4a...‌ and https://community.canvaslms.com/groups/canvas-developers?sr=search&searchId=2d86f25b-2801-40e9-9970-...‌ groups to increase its visibility and in hopes that someone can provide useful insight.  If you have not already done so, you might consider joining these user groups as well.

All the best!

bneporadny
Community Champion

 @srihari_n_yenam ‌,

You can accomplish this by using the list-users-in-course‌ api‌

Courses - Canvas LMS REST API Documentation 

 Another thing you can use is the live api‌ to test you call without having to write any code and see the results you would receive back from the call.

Canvas Live API 

Hope this helps.

jschaffer
Community Champion

 @srihari_n_yenam ‌,

You can probably approach this one of two ways, depending on how you will apply the data.  The easiest way I could see would be to run a canned provisioning report from Canvas for enrollments.  This should list the students, instructors, TAs, etc. in a given course and term, and from there you can filter the CSV for the section you want.  You can do this by going to the Admin Sheild => Settings => Reports => Provisioning => Enrollments => Filter by term => Export.

However, to approach this programatically (full disclosure I am not a coder so this may be a primitive approach), would be to first get the sections for a course (assuming you already had the course IDs handy) with:

api/v1/courses/course_id/sections

Then, using the json response, and section ID from that call, make the next call for enrollments by section with:

api/v1/section/section_id/enrollments

As  @bneporadny ‌ mentioned above, you will definitely want to check out the documentation as there are different parameters and calls you can make to get the specific information  you need. 

I hope this helps.

Jason Schaffer

pklove
Community Champion

If your Canvas sections have SIS IDs, then you can get the enrolments for a specific section with:

     /api/v1/sections/sis_section_id:$sisid/enrollments

You can limit these to student enrolments with the type parameter.

Or  you can call the course endpoint and specify specific sections.

See Enrollments - Canvas LMS REST API Documentation 

As you say you are very new to this, one thing a lot of people miss is pagination, make sure you read Pagination - Canvas LMS REST API Documentation and also the different ways of referring to objects: Object IDs, SIS IDs, and special IDs - Canvas LMS REST API Documentation 

Thank you for your response! I was looking under list-users-in-course, and I couldn't seem to find any mentions of sections under that part of it, but I'm not sure how I would go about implementing it anyways. Also, I'm having trouble understanding how to test using the live API. Sorry for the very basic questions, but I'm very new to this. Thank you for your help!

Hi  @srihari_n_yenam ‌,

When you go to the live api‌ web page at the top of the screen you will need to entered in your authentication token

271432_pastedImage_2.png

Once you have entered in your authentication token and clicked the Save token button you will want to scroll down until you see the enrollment api section and click on the one shown in the screen shot below.

271472_pastedImage_3.png

Once there scroll down and you will see where you can entered in the Canvas course SIS ID

271473_pastedImage_4.png

Entered in the Canvas course SIS ID (you may have to go to the course and find it in the URL 271474_pastedImage_5.png

Once you have entered in the course_id click try it out and you will see the json‌ results you would receive back if you called it via code. 

I have found using the #live api‌ page very useful in testing out Canvas's API's and ensuring I am going to be calling the correct one prior to putting any development time.

Hope this helps. 


Brian

 @bneporadny ‌,

Good point here.  I like to use Postman to test out my APIs and calls as well.  That way I can build collections, share code, and track my progress prior to development. 

Jason Schaffer

Thank you so much for your help!