After an outage on September 1, the Instructure Community is now fully available, including guides, release notes, forums, and groups. If some styling still looks unusual, clear your cache and cookies.
Found this content helpful? Log in or sign up to leave a like!
Hello developers,
For a statistics project for our school I'm currently interested in discovering how many of our students actually complete their courses. A course is considered completed if the student has been awarded more than 80% of the available points in the course, so in order to evaluate how many students complete their courses I need to calculate how many students, per course, who have been awarded more than 80% of the available points.
This has turned out to be a lot more complicated than I initially assumed it would be. I've tried a few approaches:
Since the number(s) that I'm trying to fetch are already in the system, I feel like I'm missing something and that this should be an easy request to make with the API. Did I overlook something? Any suggestions would be very much appreciated. 🙂
Thanks in advance,
Michael
Solved! Go to Solution.
The enrollments API is probably what you're looking for. It includes each enrollment as well as a student's current grade and final grade as calculated by Canvas. Here's what I get by doing a GET request to /api/v1/courses/123/enrollments:
[
{
"id": ...,
"user_id": ...,
"course_id": ...,
"type": "StudentEnrollment",
"created_at": ...,
"updated_at": ...,
"associated_user_id": null,
"start_at": null,
"end_at": null,
"course_section_id": ...,
"root_account_id": 1,
"limit_privileges_to_course_section": false,
"enrollment_state": "active",
"role": "StudentEnrollment",
"role_id": 3,
"last_activity_at": ...,
"last_attended_at": null,
"total_activity_time": ...,
"sis_import_id": ...,
"grades": {
"html_url": ...,
"current_grade": "B+",
"current_score": 88.6,
"final_grade": "B+",
"final_score": 88.6,
"unposted_current_score": 88.6,
"unposted_current_grade": "B+",
"unposted_final_score": 88.6,
"unposted_final_grade": "B+"
},
"sis_account_id": ...,
"sis_course_id": ...,
"course_integration_id": null,
"sis_section_id": ...,
"section_integration_id": null,
"sis_user_id": ...,
"html_url": ...,
"user": {
"id": ...,
"name": ...,
"created_at": ...,
"sortable_name": ...,
"short_name": ...,
"sis_user_id": ...,
"integration_id": ...,
"sis_import_id": ...,
"login_id": ...
}
}
]
You can also add ?include[]=current_points to the end to get the raw points value of the student's enrollment.
You'd probably want to use the unposted_current_score for your report since it's the percentage that the instructor sees in the gradebook and would be the most likely value they'd use when entering grades into SIS manually (if that's relevant to you).
Enrollments API: https://canvas.instructure.com/doc/api/enrollments.html#method.enrollments_api.index
The enrollments API is probably what you're looking for. It includes each enrollment as well as a student's current grade and final grade as calculated by Canvas. Here's what I get by doing a GET request to /api/v1/courses/123/enrollments:
[
{
"id": ...,
"user_id": ...,
"course_id": ...,
"type": "StudentEnrollment",
"created_at": ...,
"updated_at": ...,
"associated_user_id": null,
"start_at": null,
"end_at": null,
"course_section_id": ...,
"root_account_id": 1,
"limit_privileges_to_course_section": false,
"enrollment_state": "active",
"role": "StudentEnrollment",
"role_id": 3,
"last_activity_at": ...,
"last_attended_at": null,
"total_activity_time": ...,
"sis_import_id": ...,
"grades": {
"html_url": ...,
"current_grade": "B+",
"current_score": 88.6,
"final_grade": "B+",
"final_score": 88.6,
"unposted_current_score": 88.6,
"unposted_current_grade": "B+",
"unposted_final_score": 88.6,
"unposted_final_grade": "B+"
},
"sis_account_id": ...,
"sis_course_id": ...,
"course_integration_id": null,
"sis_section_id": ...,
"section_integration_id": null,
"sis_user_id": ...,
"html_url": ...,
"user": {
"id": ...,
"name": ...,
"created_at": ...,
"sortable_name": ...,
"short_name": ...,
"sis_user_id": ...,
"integration_id": ...,
"sis_import_id": ...,
"login_id": ...
}
}
]
You can also add ?include[]=current_points to the end to get the raw points value of the student's enrollment.
You'd probably want to use the unposted_current_score for your report since it's the percentage that the instructor sees in the gradebook and would be the most likely value they'd use when entering grades into SIS manually (if that's relevant to you).
Enrollments API: https://canvas.instructure.com/doc/api/enrollments.html#method.enrollments_api.index
Ah, that's it. It seems I've been working with it before but I completely forgot there was grades data in this object - thanks a lot! 🙂
A quick question.
Regarding item 2 -- using the Grades Report -- if the Grades Report has what you need, then why use the API at all? You said that if you could get the CSV generated by the report, it would be sufficient. I'm assuming that you have admin rights since you are familiar with the report. Without admin rights, you would only be able to get the data for your students.
You can request a report through the API. Through the web interface, it emails a message when the report is done, which isn't suitable for API, but might be okay in a one-off. However, you should be able to save your report ID and then check the status periodically to wait until it's finished. Then use the file_url to download the report. Note that the file_url is probably not an API call, so you don't want to include the authorization header on it.
Still, if this is something that you just need once, or even once a semester, it seems that going the easy route would save a lot of headache and time.
The enrollments report that @DecoyLex mentioned would need to be called for each course and then you would have to compile the results together into something usable.
True, but the whole hurdle is it has to happen automatically ie. programmatically since I'm building an application that will update on its own. A lot of the statistical data on display in the application can already be accessed by administrators and instructors, but in order for them to get the actual numbers and information that they need, they often have to request reports from various sources and combine datasets in spreadsheets on their own. So I'm mainly building for convenience and for automation of administrative tasks. If I have to manually feed the application with data it defeats the point. But yeah, if it was one-off, I'd just use the grades report like you say.
To 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