jdammeier
New Member

Can anyone help with pulling current grades for specific list of users using the API?

I am new to the Canvas API and have basic python understanding.

I can successfully make the API call to get course data with the enrollment grades for a user in JSON format.

https://<domain>.instructure.com/api/v1/users/<user_id>/courses.json?include[]=total_scores&enrollme...

I just need to get the following data for courses in the active term for a specified list of students:

  • Course Title
  • computed current score
  • computed current grade

Trying to figure out the best way to parse the JSON data to get this information. Would anyone thsat has done something similar be willing to lend a hand?

Labels (1)
14 Replies
jschaffer
Community Champion

 @jdammeier ‌,

I have not seen anyone respond to this yet, so maybe my crude approach may help you a bit.  I can think of a few ways to approach this depending on the scope of your request.  There is a canned report in Canvas that will export all Grades for a given term for you:

If you go into Settings => Reports for your Canvas account, you should see the Grade Export Report:

263709_pastedImage_1.png

However, if you want a more surgical approach, you can use the Enrollment Report (under the Provisioning header) to get an idea of who is enrolled in which course:

263726_pastedImage_3.png

From there you can either run your script above, or iterate over the enrollments list to pull the v1/courses/course_id/analytics/users/student_id/assignments data to get  what you need. 

However, I would make sure you account for pagination and add the parameter of per_page=100 to your call so that you get the entire scope of assignments.  I hope this helps.

Regards,

Jason

stuart_ryan
Coach Emeritus

Hi  @jdammeier ,

jschaffer has suggested one way to get access to the data. Another way I have found when I first started researching this for our institution is another option although somewhat less intuitive initially.

The data I think you are looking for is available on the Enrolments API Enrollments - Canvas LMS REST API Documentation

The Enrolments call contains:

grades": null,  
// optional: The student's score in the course, ignoring ungraded assignments. 
// (applies only to student enrollments, and only available in course endpoints) 
"computed_current_score": 90.25, 
// optional: The student's score in the course including ungraded assignments with 
// a score of 0. (applies only to student enrollments, and only available in course 
// endpoints) 
"computed_final_score": 80.67, 
// optional: The letter grade equivalent of computed_current_score, if available. 
// (applies only to student enrollments, and only available in course endpoints) 
"computed_current_grade": "A-", 
// optional: The letter grade equivalent of computed_final_score, if available. 
// (applies only to student enrollments, and only available in course endpoints) 
"computed_final_grade": "B-", 
// optional: Indicates whether the course the enrollment belongs to has grading 
// periods set up. (applies only to student enrollments, and only available in 
// course endpoints)

Depending on how you are approaching this, You can either loop through each course, grab your list of enrolled students then for each student grab the actual enrolment. Or you can check out the other features of the Enrolments API and you may be able to use 'List Enrolments' by UserID and then loop through the Enrolments.


My personal preference is to go based on 'List Enrolments' by Course, as that means you won't un-necessarily loop through older courses that have no need to be processed, rather than constantly looping through every user on your instance.

Does that help at all? I was not completely sure if you were looking at needing a different API call moreso than guidance on using the API with Python, please let me know.

I know this particular use case was something that took me quite a while to get my head around initially, we are still in the process of looking at building this through this year.

Cheers,

Stuart

Hi Stuart,

Thanks so much for the reply. I was able to successfully parse the JSON data with python to generate the report I needed. I just forgot to come back and update this thread. Please let me know if you'd like to see a sample of the code I wrote.

Justin

baxl
Community Contributor

Hi  @jdammeier ‌, can you share your sample code? I have something similar that came up and this might help.

0 Kudos

Hi Lisa,

Here is the sample code I have. https://gist.github.com/jbdammeier/c01a6ec0d64339d363f04b93f8208c41

WIndows task scheduler runs it at specified times. It is written in Python 3.6.2.  Take a look and let me know if you have any questions. I'm sure there is a simpler way to do this, but it works for us. 

Hope it helps!

Justin

 I have 2 problems when I try to get grades. 

The first is that only 10 of the ~30 enrollments are returned, and

the second problem is that all of the grades show "None".  I'm just doing 1 API call:

https://extendutexas.instructure.com/api/v1/courses/88/enrollments

I'm using the python requests library, so:

enrollments = response.json()

Then:

for enrollment in enrollments:
   print(enrollment['enrollment_state'], enrollment['user']['name'], enrollment['role'], " ", end='')
   if enrollment['role'] == 'StudentEnrollment':

      print(enrollment['grades']['final_score'], enrollment['grades']['unposted_final_score'])
   else:
      print("Not a student")

0 Kudos

Hi  @wmonroe ,

You seem to have a different question to what was posted. I would suggest you log a new question in the community in future. Doing so ensures your question gets the correct attention and also makes sure we can focus on the original poster's question here.

Please have a look through Canvas APIs: Getting started, the practical ins and outs, gotchas, tips, and tricks specifically the Pagination Concepts section --> https://community.canvaslms.com/docs/DOC-14390-canvas-apis-getting-started-the-practical-ins-and-out...

You will need to ensure you handle pagination correctly to retrieve more than the default single page output.

If you have any follow up questions, please log a new question in the Canvas Developers‌ space.

Hope that helps!

Stuart

0 Kudos

Got it.  New to this community.  Happy to post a new question.  I figured the limited number of records was related to Pagination. 

All good! I know it can be fun learning the ins-and-outs of a new community. Always happy to guide and not a problem at all!

0 Kudos
stuart_ryan
Coach Emeritus

Hi  @jdammeier ,

No worries at all, it would be great to see the sample code you wrote. Having sample code available for others to look at is always incredibly helpful!


Thanks so much for the update!

Cheers,
Stuart

Boekenoogen
Community Contributor

We have built a Google Sheets that will call student grades for all courses by entering their SISID. If you want us to share it, let me know. 

Hi  @jrboek ‌,

I would be very curious to see this myself please!

Cheers,
Stuart

0 Kudos

Hi  @jrboek ,

I would be interested in seeing this as well.

Thanks,

Justin

0 Kudos

Here is a link to the Google Sheet.

Student Grade Lookup - Google Sheets  

0 Kudos