Using Course API to get grades

3,301 views
Skip to first unread message

Sean Keesler

unread,
Jan 18, 2012, 4:31:31 PM1/18/12
to Canvas LMS Users
I am attempting to use the API to get final grades of all students in
a course.

When I use the following:
https://ourinstance.instructure.com/api/v1/courses?include[]=total_scores&access_token=myToken

I get JSON that includes a course am the Teacher of:

[
{
"name":"Sean Sandbox",
"id":269137,
"enrollments": [{"type":"teacher"}],
"course_code":"Course-101",
"sis_course_id":"SIS-1",
"calendar":{"ics":"https://ecornell.instructure.com/feeds/calendars/
course_A37CHlodlyipEEXVten5PPOKaEhO6ilNRiy0N40A.ics"}
}
]

But the students (nor their grades) seem to show up in the results.
Why would that be?

Sean Keesler
Business Analyst
eCornell

Tom Metge

unread,
Jan 18, 2012, 4:40:53 PM1/18/12
to canvas-l...@googlegroups.com
sean-

here's an example of pulling final grades from Canvas:


the first link is a summary with some instructions on using the next link- the script that actually does the job.

as you'll see in the above examples, you need to get a list of assignments per course, then pull the submissions (which have the scores) for each assignment.

you can parallelize this, if you need it to run more quickly. you'll notice that the example provided aggressively writes aggregated results out to a CSV file- i would recommend not storing everything in memory, especially if the institution size is large.

good luck!

t

Sean Keesler

unread,
Jan 19, 2012, 4:42:11 PM1/19/12
to Canvas LMS Users
I was able to pull some individual assignment scores from Canvas using
the API via this method, but what I REALLY want is the final score so
that I can store that piece of data elsewhere. The API seems to
suggests that this is possible.

Sean



On Jan 18, 4:40 pm, Tom Metge <t...@instructure.com> wrote:
> sean-
>
> here's an example of pulling final grades from Canvas:
>
> https://gist.github.com/1364717https://gist.github.com/1364715

Patricia Goldweic

unread,
Nov 4, 2016, 2:04:04 PM11/4/16
to Canvas LMS Users
Have you ever been able to pull the final course grades without going through the trouble of retrieving assignments? If so, could you please explain how? Thanks!

Christopher Bennell

unread,
Nov 7, 2016, 10:11:08 AM11/7/16
to Canvas LMS Users
You can use the "List Users in a Course" API with include[] => 'enrollments'.

Here's some pseudo-code: 

url = "courses/sis_course_id:#{sis_id}/users"
params = {
  'include[]'       => 'enrollments',
  'enrollment_type' => 'student',
}
canvas_client.get(url, params).each do |user|
  grades = user['enrollments'][0]['grades'] 
end

In this example grades will be a hash with keys current_score, current_grade, final_score and final_grade. The final_score will be the grade for the course, with ungraded assignments treated as zeros. current_score is the grade-to-date. 

Patricia Goldweic

unread,
Nov 7, 2016, 2:15:58 PM11/7/16
to Canvas LMS Users
Thanks Christopher! Looks like this API call gives you exactly the same as what you get using the enrollments API instead, with url:
"courses/sis_course_id:#{sis_id}/enrollments" (as I found out after I posted this question), since the Enrollment object also has a 'grades' object which is exactly as you describe.
Thanks again
Reply all
Reply to author
Forward
0 new messages