Administrators at our high school want to be able to turn off messaging for just certain students. I can do this by manually deleting their current "Student" enrollments and adding them back to their classes as our custom course user role "Restricted Student" for whom we have taken away permissions for messaging.
But the nightly sync with our SIS (PowerSchool via SIF to Kimono) reverts these changes.
So I need to automate this to run each night. I found a way with 2 CSV uploads called by cURL via the API.
This is cool and very powerful since I can do everything the CSV uploads can, but seems like overkill.
Is there an API call that would let me make the changes without the CSV?
What I imagine is that my SIS could crank out a nightly file of students marked to restrict, then a python script reads the entries on that file (course section and student) and either:
1. Changes the course role like we can in the UI (is there an API call for this - like a PUT for the roleid? This is not in the LiveAPI, but are there some that are not?),
2. (like my CSVs) deltes the SIS-created "Student" enrollment and and re-adds the student as our custom "Restricted Student" (I know that there are API calls for these, but I do not know how to use my SIS-generated information (canvas sectionid and canavs userid) to do this - the delete call in the API appears to need canvas course id - since we have many cross-listings, this might not be possible - will i have to make and parse a first call to get the users courseIDs?
thanks for any thoughts on this. i have just been telling them "not possible" for several years, but now that I can leverage the API, it is - just want to do it efficiently.
There are many approaches you can take, some of which eliminate the need to send updates each night. I have not used PowerSchool, so some of these may not be possibilities for you. This is a non-exhaustive list.
When uploading CSV files through the SIS import process, you have the option to override (or not) changes made through the UI. You also have the ability to make the changes sticky, which is what happens when changes are made through the UI. If you have control over the settings, you could upload the CSV for the restricted enrollments and use the add_sis_stickiness parameter (you may need to use the override_sis_stickiness as well). Then make sure that PowerSchool does not use the override. There wouldn't be a need to update nightly, only when enrollments for those restricted students change.
This may take some tweaking, you might need to send a deleted status with the stickiness parameter for the student enrollment. It may also be sufficient (I haven't tested) that marking the deleted status as sticky for the student enrollment works without changing the status on the restricted enrollments. Since users can have multiple enrollments within a course, Canvas would likely see the student enrollment and restricted enrollment as two separate enrollments and since PowerSchool doesn't know about the restricted enrollment, it would never try to delete it (and so you wouldn't need to mark it as sticky).
You can specify custom roles with the CSV import and you can automate the CSV imports through the API. If you cannot change the settings on the PowerSchool import, then you could wait until it had been processed and then run a second import of the restricted students. This potentially creates a delay between when the PowerSchool import runs and your custom import runs. That would leave the students able to send messages during that time.
I do not know whether imports are processed in sequence, but there is a comment under the abort SIS import endpoint that suggests that only one is processed at a time. If you were sure that the PowerSchool import had started processing, then you might be able to upload the custom import right away. I don't do this myself (I always check the status before sending a new import and refuse to send the new one if the old one hasn't finished) so I cannot verify that.
If you have a few students with this restriction, you can use the Enrollments API to make the changes. If you have a lot of students and are already using the CSV import (you are through PowerSchool), I would recommend sticking with one of the first two options.
First, enroll a user with the restrictions so they are in the course twice. Enrolling by the custom role name is marked as deprecated, so you'll need to the custom role ID. Then use the conclude, deactivate, or delete an enrollment endpoint to remove the access for the regular student enrollment. You might think that you should delete first and then add, but I'm trying to avoid the situation where the student gets deleted and then something happens and they don't get added back or they're in the middle of a quiz and get booted or something else bad.
I don't use Canvas' cross-listing mechanism (I wrote my own system), but enrollments can be made at the course level or the section level, so you would want to mimic what was done via the CSV uploads.