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
Hello, I am trying to query a course ID to check if it was cross listed. Do you know what is the data field to get this information or what query or API endpoint to use? I tried to use nonxlist_course_id, but received error 'doesn't exist on type course'.
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…
A case for this argument: I live in thee K-12 realm which means we have way too many assignments... which means that at times a simple last 10 assignments of a course question(last 10 date wise) will take us 300 assignments to answer Solution for this example in particular: I would love to make this modified version of an…
Hey Community: I want to ask first if Canvas LMS as a Identity provider is only supported with SAML? What other protocols are supported? My use case is that I have a React App hosted on cloud provider (AWS) and SpringBoot as a backend (Service provider). I want to integrate Canvas SSO as a Identity provider (IdP). I…
Hi , I’m working on validating the API test cases for CANVAS Api and need suitable test data to verify the 200 OK status code responses. I am using free for teachers version account. PFA Ecel sheet about the end points I am checking for.