This vignette demonstrates how to upload a QTI file to Canvas LMS,
retrieve the ID of the newly created quiz, and update quiz parameters
using R. The process involves using the
upload_qti_file_with_migration
,
get_course_quizzes
and update_quiz
functions.
First, authenticate with Canvas by creating a canvas object containing your API key and base URL:
Set the course in which the upload must take place and retrieve the list of quizzes already available before uploading the new QTI file into the course:
The time that Canvas requires to process the uploaded QTI file is hard to predict. It depends on the traffic on the Canvas server, and possibly the number of migrations the user has recently performed. Therefore, in circumstances with much waiting time a different approach is advised than when waiting time is short. In the latter case the ID of the quiz is easily obtained, and in the former case the ID needs to be determined using a more extensive approach requiring two additional steps.
If processing takes little time (e.g., 5 to 10 seconds), one can
obtain the ID of the quiz directly using the
upload_qti_file_with_migration
function setting
wait = TRUE
, by which the function waits 30 seconds after
uploading the QTI file to check if it has been converted into a new
quiz. If a new quiz has been created it returns the ID of the quiz; if
not it asks the user if further waiting is required. Assuming the QTI
file, stored in the working directory, is called “qti_file.zip”, the
following code may be used:
qti_name <- "qti_file" # Replace with your actual file name
quiz_id <- upload_qti_file_with_migration(canvas, course_id, qti_name, wait = TRUE)
Note that if this route is successful, one can directly go to step 6.
By contrast, if one prefers or is forced to use the extensive approach, it is advised to use the following code, which also requires steps 4 and 5:
For the extensive approach it is advised to wait sufficient time to make sure the QTI is converted into a quiz (sometimes it takes one or two hours). Next, retrieve the list of quizzes again after the QTI file upload using:
Compare the lists of quizzes before and after the upload to identify the ID of the newly created quiz:
Use the update_quiz function to modify the parameters of the newly created quiz:
This vignette demonstrated how to upload a QTI file to Canvas LMS, identify the newly created quiz, and update its parameters. You can extend this process to modify other quiz attributes as needed.