I have an enrollments.csv file for Instructure’s Canvas LMS, and I want all of the enrollments in it to “stick”–that is, to survive a batch mode SIS import. These are primarily course designers, and so they have no official standing in the class–and therefore are not in our database, and therefore are not included with regular updates to enrollments.
According to the Canvas documentation for SIS imports:
add_sis_stickiness – Boolean
This option, if present, will process all changes as if they were UI changes. This means that “stickiness” will be added to changed fields. This option is only processed if ‘override_sis_stickiness’ is also provided.
Source: https://canvas.instructure.com/doc/api/sis_imports.html#method.sis_imports_api.create
However, experience tells me otherwise. An inquiry to Instructure’s support confirms that add_sis_stickiness does not apply to enrollments. Enrollments added this way will be deleted following the next enrollments batch import.
The choices to preserve these course designer enrollments are basically to add each one manually using the web UI, or add them via the API. Either option will make the enrollments “stick.”
I opted to use the API. Since I already had a formatted input file, I wrote a short BASH script (with the help of several man pages and a couple StackOverflow pages) that reads the CSV and processes each row, adding the enrollment via the API:
headerrow=1
while read row; do
if [ $headerrow -eq 0 ]
then
# get the SIS course ID
cid="$(echo $row | cut -d',' -f1)"
# get the SIS user ID
uid="$(echo $row | cut -d',' -f2)"
# get the role / enrollment type
type="$(echo $row | cut -d',' -f3)"
# reformat the enrollment type
tid="$(echo $type | cut -c1 | tr [[:lower:]] [[:upper:]])""$(echo $type | cut -c2-)"Enrollment
echo course is $cid
echo user is $uid
echo type is $tid
result="$(curl https://[yourcanvassite].instructure.com/api/v1/courses/sis_course_id:$cid/enrollments -H 'Authorization: Bearer [REDACTED]' -X POST -F enrollment[type]=$tid -F enrollment[user_id]=sis_user_id:$uid -F 'enrollment[enrollment_state]=active' -F 'enrollment[notify]=false')"
echo $result
fi
headerrow=0
done <enrollments.csv