My biggest complaint when using the Canvas API is the inordinate amount of pointing and clicking that it requires to get anything done. Here are some examples of such tasks that are easily automated using the cnvs package.
Right now this is a work in progress to help me think about what a higher level API might look like
I’ll demonstrate with one of my own courses:
test_course <- 1732420
The code won’t work for you because you don’t have permissions on my course. I recommend creating your own test course on https://canvas.instructure.com/, and substituting in your own course ID.
Problem: You have ten homeworks due every Friday that you want students to submit online.
Canvas API docs: https://canvas.instructure.com/doc/api/assignments.html#method.assignments_api.create
Start by generating a tibble to hold the parameters of your homeworks, being careful to have dates in the ISO 8601 format canvas expects:
iso8601 <- lubridate::stamp("2014-10-21T18:48:00Z") #> Multiple formats matched: "%Y-%Om-%dT%H:%M:%SZ"(1), "%Y-%m-%dT%H:%M:%SZ"(1), "%Y-%Om-%dT%H:%M:%S%Ou"(1), "%Y-%m-%dT%H:%M:%S%Ou"(1) #> Using: "%Y-%Om-%dT%H:%M:%S%Ou" hws <- tibble( week = 1:10, name = paste("Homework", week), due = (lubridate::ymd_hm("2019-09-27 23:59", tz = "America/Los_Angeles") + lubridate::weeks(week - 1)) %>% iso8601() ) hws #> # A tibble: 10 x 3 #> week name due #> <int> <chr> <chr> #> 1 1 Homework 1 2019-09-28T06:59:00Z #> 2 2 Homework 2 2019-10-05T06:59:00Z #> 3 3 Homework 3 2019-10-12T06:59:00Z #> 4 4 Homework 4 2019-10-19T06:59:00Z #> 5 5 Homework 5 2019-10-26T06:59:00Z #> 6 6 Homework 6 2019-11-02T06:59:00Z #> 7 7 Homework 7 2019-11-09T07:59:00Z #> 8 8 Homework 8 2019-11-16T07:59:00Z #> 9 9 Homework 9 2019-11-23T07:59:00Z #> 10 10 Homework 10 2019-11-30T07:59:00Z
Creating a single homework assignment with cnvs would look like:
one_hw <- cnvs("POST /api/v1/courses/:course_id/assignments", course_id = test_course, assignment = list( name = hws$name[[1]], due_at = hws$due[[1]], points_possible = 10, submission_types = list("online_upload") ) )
To create them all, leverage purrr::map2
all_hws <- map2(hws$name, hws$due, ~ cnvs("POST /api/v1/courses/:course_id/assignments", course_id = test_course, assignment = list( name = .x, due_at = .y, points_possible = 10, submission_types = list("online_upload") ) ) )
Delete them all if you want:
Problem: You have a whole directory of files on your local computer you want to put in a course on Canvas, preferably maintaining your directory structure.
Let’s say I have some lectures and worksheets on my local computer:
#> .
Problem: You’ve copied over an old course where you released solution files. You now want to make sure that these files are all now unpublished for the new term.
Problem: You want to post your own reply in every group’s discussion board, e.g. an introduction post in a group introduction discussion.
Problem: You’ve copied over an old course where you used groups from some discussions. Canvas has copied over the group set, but it doesn’t have any students assigned to the groups. You could assign students to the old groups in the old group set, but you would rather set up a new group set that randomly assigns students to groups, then use this new group set for all the discussions.