API Unenroll from a Class via SIS User ID

breilly1
Community Member
2
1726

I looked in the forum and couldn't find the answer.

Is it possible to unenroll a user from class use the SIS UserID?  It seems like I will need to search for the enrollment ID to do it and I'd rather skip that step.

TIA

Boyd

2 Comments
James
Community Champion

@breilly1 

You can add a student by user ID, so you would think that you would be able to remove a user as well, right? It only makes sense that deletion would work the same way.

However, there is a piece of information missing here.

When you add a student, you have to specify whether you are adding them to a course or section in the pathname. The URL to delete an enrollment doesn't support that, it just has the enrollment ID and a task.

There's something else going on as well. A student may be enrolled in a course multiple times in different sections or with different roles. An enrollment is keyed to a user/role/section triplet -- change any one of those and you have a different enrollment.

You likely would want to remove them completely from the course, but the API has to allow for you removing them from one section but leaving them in another section. That means there needs to be a specific way to conclude just the single enrollment. Hence the requirement to give the enrollment ID vs some other combination of things.

I guess the short answer is no, but understanding why things are the way they are can help with acceptance.

Note that when you delete a student from within the web interface, it does not directly call the API. It calls an internal route that does use the course ID. However, it does not use the student ID, it still uses the enrollment ID because the student might be enrolled in multiple sections and it needs to know which one to remove them from.

If you use the "Remove user from course" method from the People page and a student is enrolled multiple times, it still makes a separate call for each role/section combination. That is, Canvas still bases it off of the enrollment ID, even though it's not an API call and they could have extra functionality, including deleting all enrollments at the same time.

breilly1
Community Member
Author

James:

Thanks for the response. 

I can always get the enrollment ID via the user enrollments end point.  Not the extra step I wanted to take, but that's good to know.

Boyd