Script for allowing users to remove themselves from courses?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Colorado State seems to have a script that allows faculty to remove themselves from unneeded courses: How to remove yourself from unneeded courses - Canvas Information and Resources - Colorado State Uni...
I contacted their support for more info but didn't get an answer. Anyone have info on a script like this? I'm currently in around 300 courses and growing and don't have permission to remove myself. Others are in a similar boat. The only docs I can find are for self-enroll courses, which provide an unenroll link. I can remove others from courses, but not myself. I made a Google sheet using the Canvas API to delete my enrollments but got a permission error.
Or is this something I should feature request?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
here's a Windows Powershell script that will delete you from all of your courses.
As @stuart_ryan says it's likly a filter is needed to not remove you from some courses.
The hard part seams to be getting permission to do the thing you want to do.
#sets permission to make api call
$token = "1234~sdkgffdjklfjfkdlgjklfsdjklgjklklfsdkljklgklfsdgklfdklgjklfsdklgg" #token Note this token is fake repalce it with your one or one that has permission to do the thing you want it to do.
$domain = "lorainccc.instructure.com" #change to your instution.
$headers = @{"Authorization"="Bearer "+$token}
#extra data
$date = Get-Date -Format "yyyy-MM-dd"
$logPath = "Y:\Canvas\Canvasfileload\logs\"
$userid = "sis_user_id:12345" #Replace 12345 use this if you know your instutional Canvas ID.
#or
#$userid = "12345" #Replace 12345 with your ID
#Api call for listing your enrollments Which gets us a list of course_IDs to remove from.
$listenrollmentapi = "/api/v1/users/$userid/enrollments?per_page=50"
$url = "https://$domain$listenrollmentapi"
$listenrollmentesults = Invoke-RestMethod -Headers $headers -Uri $url -Method GET
#reivew the enrollments and delete each one.
foreach($enroll in $listenrollmentesults)
{
$course_id = $enroll.course_id
$deleteenrollmentapi = "/api/v1/courses/$course_id/enrollments/$userid"
$url = "https://$domain$deleteenrollmentapi"
$deleteenrollmentresults = Invoke-RestMethod -Headers $headers -Uri $url -Method DELETE
}