knitr::opts_chunk$set( collapse = TRUE, comment = "#>", eval = FALSE )
library(vvcanvas)
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:
canvas <- vvcanvas::canvas_authenticate()
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:
course_id <- "12345" # Replace with your actual course ID quizzes_before <- get_course_quizzes(canvas, course_id)
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:
qti_name <- "qti_file" # Replace with your actual file name upload_qti_file_with_migration(canvas, course_id, qti_name)
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:
quizzes_after <- get_course_quizzes(canvas, course_id) print(quizzes_after)
Compare the lists of quizzes before and after the upload to identify the ID of the newly created quiz:
quiz_id <- setdiff(quizzes_after, quizzes_before) print(new_quiz)
Use the update_quiz function to modify the parameters of the newly created quiz:
quiz_params <- list( title = "Updated Quiz Title", description = "Updated description of the quiz.", due_at = "2013-01-23T23:59:00-07:00", published = TRUE ) updated_quiz <- update_quiz(canvas, course_id, quiz_id, quiz_params) print(updated_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.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.