Bulk Update Default View in Courses

Document created by Amber Batten on May 8, 2018
Version 1Show Document
  • View in full screen mode

Here is a script that will take a csv of course SIS IDs and update the default view for all of the SIS IDs to wiki pages.  You can, of course, change the assignment of default view to any of the other parameters.

 

# import gems
require 'typhoeus'
require 'json'
require 'csv'

canvas_url = '' # put full canvas test url eg: https://school.test.instructure.com
canvas_token = '' # put canvas API token here'
csv_file = '' # full path to csv file  eg: full/path/to/file/api_courses.csv
default_view = "wiki" #can also use other parameters such as feed, modules, syllabus, assignments


CSV.foreach(csv_file, headers: true) do |row|
    sis_course_id = row['course_id']


    update_course = Typhoeus::Request.new(
        "#{canvas_url}/api/v1/courses/sis_course_id:#{sis_course_id}",
        headers: { authorization: "Bearer #{canvas_token}" },
        method: :put,
        params: {
            "course[default_view]" => default_view
        }
        )
        update_course.on_complete do |response|
            if response.code == 200
                data = JSON.parse(response.body)
                puts "The course_id #{sis_course_id} has been updated."
            else
                puts "Something went wrong! Response code was #{response.code}"
            end
        end
    update_course.run
end
1 person found this helpful

Attachments

    Outcomes