Does anyone have an example of how to add a user to a course via the API? I can see how to do it via browser but im trying to automate enrollment into a class.
@ScottMo We create enrollments through the API in certain cases. Using a script to create them via the API is almost as convenient as SIS Import CSVs, but the resulting enrollments can be managed by teachers. The Enrollments API also allows one to bypass the invitation step (I wish that Instructure would build this into the +People GUI workflow). Here is a template BASH script.
#!/bin/bash# Enrollment template developed by Emory University Teaching & Learning Tech.# This is a template to enroll a set of users in a set of courses or sections# Fill in the variables (no space after equal sign), save as a new file, and run# See comments before each variable for options# Institution URL stem. For FFT (canvas.instructure.com), the stem is just "canvas".url_stem=# Canvas instance: prod, test, betacanvas_instance=# Limit access to target section: "false", "true"section_limited_access=""# Enrollment targets: course, section# In general, it's best to target sections, particularly if your SIS Imports# create sections. Targeting an enrollment at a course should be safe in a# manually created course with only one section.enrollment_target=# Target ID types: sis, canvastarget_id_type=# Supply course ID or section ID values separated by spaces or new linestargets=()# Enrollment types: Student, Teacher, Ta, Designer, Observerenrollment_type=# User ID types: login, sis, integration, canvasuser_id_type=# Supply user ID values separated by spaces or new linesusers=()###### Edits to template are not typically necessary below this line ####### canvasAPItoken variable is set from file if it exists and is not empty# file not needed if variable set in environmentif [ -s ~/.canvasAPItoken.txt ]; then canvasAPItoken=`cat ~/.canvasAPItoken.txt`; fi# section_limited_access is checkedif [ $section_limited_access != "false" -a $section_limited_access != "true" ];then echo "section_limited_access must be \"false\" or \"true\". Exiting"; exit 1 ;fi# canvas_domain is determined by canvas_instance and url_stemif [ $canvas_instance == "prod" ]; then canvas_domain="$url_stem.instructure.com" ;elif [ $canvas_instance == "test" ] ; then canvas_domain="$url_stem.test.instructure.com" ;elif [ $canvas_instance == "beta" ] ; then canvas_domain="$url_stem.beta.instructure.com" ;else echo "$canvas_instance is not a valid enrollment type. Exiting"; exit 1 ;fi# enrollment_target is checkedif [ $enrollment_target != "course" -a $enrollment_target != "section" ];then echo "$enrollment_target is not a valid enrollment target. Exiting"; exit 1 ;fi# target_prefix is determined by target_id_typeif [ $target_id_type == "sis" ]; then target_prefix="sis_${enrollment_target}_id:" ;elif [ $target_id_type == "canvas" ] ; then target_prefix="" ;else echo "$target_id_type is not a valid target type. Exiting"; exit 1 ;fi# enrollment_role_id is determined by enrollment_type. Customize this block # to swap out default roles with custom roles or just add some custom roles. if [ $enrollment_type == "Student" ]; then enrollment_role_id=3 ;elif [ $enrollment_type == "Teacher" ] ; then enrollment_role_id=4 ;elif [ $enrollment_type == "Ta" ] ; then enrollment_role_id=5 ;elif [ $enrollment_type == "Designer" ] ; then enrollment_role_id=6 ;elif [ $enrollment_type == "Observer" ] ; then enrollment_role_id=7 ;else echo "$enrollment_type is not a valid enrollment type. Exiting"; exit 1 ;fi# user_prefix is determined by user_id_typeif [ $user_id_type == "login" ]; then user_prefix="sis_login_id:" ;elif [ $user_id_type == "sis" ] ; then user_prefix="sis_user_id:" ;elif [ $user_id_type == "integration" ] ; then user_prefix="sis_integration_id:" ;elif [ $user_id_type == "canvas" ] ; then user_prefix="" ;else echo "$user_id_type is not a valid user ID type. Exiting"; exit 1 ;fifor user_id in ${users[@]}dofor target_id in ${targets[@]}doecho "Attempting to enroll $user_id in $target_id"api_response=`curl -s -S https://$canvas_domain/api/v1/${enrollment_target}s/$target_prefix$target_id/enrollments \-X POST \-F "enrollment[role_id]=$enrollment_role_id" \-F "enrollment[type]=${enrollment_type}Enrollment" \-F "enrollment[user_id]=$user_prefix$user_id" \-F "enrollment[enrollment_state]=active" \-F "enrollment[limit_privileges_to_course_section]=$section_limited_access" \-F "enrollment[notify]=false" \-H "Authorization: Bearer ${canvasAPItoken}"`echo "$api_response\n"donedone
I'm building a tool for my institution that imports grades from another LTI tool into Canvas so instructors can automate late assignment policies not otherwise supported by Canvas. I'm trying to use the LTIv1.3 ID which is readily available on the LTI-side as a link to the student record on Canvas, but I can't find the ID…
How can one track Canvas Media use without having the reports available from Canvas Studio? Checking API endpoints and the Data 2 schema, there do not seem to be dedicated Canvas Media endpoints. Am I missing some? A method I've considered is using the body field of the wiki_pages table, as this contains the html code of…
Hello, I'm trying to utilize an API call to pull completed certificates and was hoping to download and store the certs as a backup. I can successfully run the API call but it will not allow me to view the certificate unless I access the URL while signed into an account where it's "my" cert. Is there a permissions setting…
UI for weekly progression idea that rest in the Schedule tab of the **K-12 UI** of Canvas it's incomplete and I really would not take it and push it into instance but I am going to post it here because in the past people like @James && @robotcars || @Steve_25 have had terrific input in the past... maybe w/their eyes and…
I have a new React + Flask webapp. It has its own login for users to start using the app. I have added this as an external tool in Canvas. What I want initially is to see of canvas users can start using the webapp without having to login if they click on the external tool link in a canvas course. I have 2 methods…