{"id":1340,"date":"2016-01-15T10:48:43","date_gmt":"2016-01-15T15:48:43","guid":{"rendered":"http:\/\/osric.com\/chris\/accidental-developer\/?p=1340"},"modified":"2016-01-15T10:51:57","modified_gmt":"2016-01-15T15:51:57","slug":"canvas-enrollments-csv-and-add_sis_stickiness","status":"publish","type":"post","link":"https:\/\/osric.com\/chris\/accidental-developer\/2016\/01\/canvas-enrollments-csv-and-add_sis_stickiness\/","title":{"rendered":"Canvas enrollments.csv and add_sis_stickiness"},"content":{"rendered":"<p>I have an enrollments.csv file for Instructure&#8217;s Canvas LMS, and I want all of the enrollments in it to &#8220;stick&#8221;&#8211;that is, to survive a batch mode SIS import. These are primarily course designers, and so they have no official standing in the class&#8211;and therefore are not in our database, and therefore are not included with regular updates to enrollments.<\/p>\n<p>According to the Canvas documentation for SIS imports:<\/p>\n<blockquote><p>\nadd_sis_stickiness &#8211; Boolean<\/p>\n<p>This option, if present, will process all changes as if they were UI changes. This means that \u201cstickiness\u201d will be added to changed fields. This option is only processed if &#8216;override_sis_stickiness&#8217; is also provided.\n<\/p><\/blockquote>\n<p>Source: <a href=\"https:\/\/canvas.instructure.com\/doc\/api\/sis_imports.html#method.sis_imports_api.create\">https:\/\/canvas.instructure.com\/doc\/api\/sis_imports.html#method.sis_imports_api.create<\/a><\/p>\n<p>However, experience tells me otherwise. An inquiry to Instructure&#8217;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.<\/p>\n<p>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 &#8220;stick.&#8221;<\/p>\n<p>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:<\/p>\n<pre><code>headerrow=1\r\nwhile read row; do\r\n    if [ $headerrow -eq 0 ]\r\n    then\r\n        # get the SIS course ID\r\n        cid=\"$(echo $row | cut -d',' -f1)\"\r\n        # get the SIS user ID\r\n        uid=\"$(echo $row | cut -d',' -f2)\"\r\n        # get the role \/ enrollment type\r\n        type=\"$(echo $row | cut -d',' -f3)\"\r\n        # reformat the enrollment type\r\n        tid=\"$(echo $type | cut -c1 | tr [[:lower:]] [[:upper:]])\"\"$(echo $type | cut -c2-)\"Enrollment\r\n        echo course is $cid\r\n        echo user is $uid\r\n        echo type is $tid\r\n        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')\"\r\n        echo $result\r\n    fi\r\n    headerrow=0\r\ndone &lt;enrollments.csv<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I have an enrollments.csv file for Instructure&#8217;s Canvas LMS, and I want all of the enrollments in it to &#8220;stick&#8221;&#8211;that is, to survive a batch mode SIS import. These are primarily course designers, and so they have no official standing in the class&#8211;and therefore are not in our database, and therefore are not included with &hellip; <a href=\"https:\/\/osric.com\/chris\/accidental-developer\/2016\/01\/canvas-enrollments-csv-and-add_sis_stickiness\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Canvas enrollments.csv and add_sis_stickiness<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[197,308,309,215],"class_list":["post-1340","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-bash","tag-canvas","tag-canvas-api","tag-curl"],"_links":{"self":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/1340","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/comments?post=1340"}],"version-history":[{"count":6,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/1340\/revisions"}],"predecessor-version":[{"id":1349,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/1340\/revisions\/1349"}],"wp:attachment":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/media?parent=1340"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/categories?post=1340"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/tags?post=1340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}