Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Function to obtain course gradebook from Canvas
get_course_gradebook <- function(course_id) {
course_assignment_ids <- get_course_items(course_id, "assignments") %>% .$id %>% as.list()
course_ids <- rep(course_id, length(course_assignment_ids)) %>% as.list()
get_assignment_submissions <- function(course_id, assignment_id) {
url <- sprintf("%s/api/v1/courses/%s/assignments/%s/submissions", canvas_url(), course_id, assignment_id)
httr::GET(url, query = list(access_token = Sys.getenv("CANVAS_API_TOKEN"))) %>%
httr::content("text") %>%
jsonlite::fromJSON(flatten = TRUE)
assignments <- purrr::map2_df(course_ids, course_assignment_ids, get_assignment_submissions)
students <- get_course_items(course_id, "enrollments") %>% dplyr::select(, user_id, grades.final_score, course_id)
dplyr::left_join(assignments, students, by = "user_id")
gradebook <- get_course_gradebook(course_id = 20) #Where course_id is a valid Canvas course id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.