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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My background is in higher ed. I currently work in K12. I miss higher ed. I'm North Carolina born and bred, but I've lived in Greenville, NC (hometown), Charlotte, NC, Winston-Salem, NC, Durham, NC and Creedmoor, NC.