Your Community is getting an upgrade!
Read about our partnership with Higher Logic and how we will build the next generation of the Instructure Community.
The purpose of this script is to add institutional calendar events to users' personal Canvas calendars.
For example, we are going to add grading period start/end dates, district holidays, and testing information to Teacher and Student Calendars.
# import gems
require 'typhoeus'
require 'json'
require 'csv'
canvas_url = 'https://XXXX.instructure.com' # put full canvas prod/test url eg: https://school.instructure.com
canvas_token = 'XXXXXXXXX' # put canvas API token here
csv_file1 = 'C:\XXXX\users.csv' #full path to users.csv
csv_file2 = 'C:\XXXX\calendar_events.csv' #full path to calendar_events.csv
start_timer = Time.now
CSV.foreach(csv_file1, headers: true) do |row|
user_id = row['id']
CSV.foreach(csv_file2, headers: true) do |row2|
calendar_title = row2['title']
calendar_date = row2['start']
update_calendar = Typhoeus::Request.new(
"#{canvas_url}/api/v1/calendar_events?as_user_id=#{user_id}",
method: :post,
headers: { authorization: "Bearer #{canvas_token}" },
params: {
"calendar_event[context_code]" => "user_#{user_id}",
"calendar_event[title]" => "#{calendar_title}",
"calendar_event[all_day]" => true,
"calendar_event[start_at]" => "#{calendar_date}",
"calendar_event[time_zone_edited]" => "America/Chicago"
}
)
update_calendar.run
end
end
finish_timer = Time.now
diff = finish_timer - start_timer
puts "Script done running! Took #{diff} seconds to run."
Install Ruby and the following gems - typhoeus, json, and csv.
These will be all day events. You could change these to be specific dates by adding time to the start date and then add a new line for end date to the script. The format for a datetime is YYYYMMDDTHHMMSSZ (Example - 20210405T063000Z). If you do add time, you'll need to update your timezone, otherwise it doesn't really matter for all day events when only using the date format.
I've not tested this on a full term yet as we will be doing it for the first time this summer as a trial and then will deploy fully in the Fall. If you need to run more than once (new users, etc.), I would diff the user file and only run against new users, otherwise you will duplicate events on everyone's calendar.
I can not support this script for you. If you do not know how to install/run a Ruby script, please utilize resources found here and on Google to help with that process.
I would like to add a checker to determine if an event with that title is already on that day and if so, skip it. If you have ideas of how to do this, please contribute and share!
Please feel free to iterate and make this better and modify for your institutional goals.
Cheers,
Chad Scott
LMS Support Specialist
Katy ISD Instructional Technology
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My current role focuses on maintaining Canvas for Katy ISD and developing new tools and trainings for users. Previously, I was a Classroom Technology Designer from 2016/2017 to 2019/2020 school years at several high schools and junior highs. I have six years of classroom teaching experience - I taught AP Environmental Science, Chemistry, and IPC at Morton Ranch HS and Miller Career & Technology Center. I graduated from Eastern Michigan University with a B.S. in Geology and minor in Environmental Science. Previous to my teaching career, I worked as an Environmental Geologist focused on groundwater and soil remediation projects. I have a passion for spreadsheets and love developing methods to increase efficiency and reduce investment in tedious tasks. I love learning - whether it's something technology related or something more traditional like making costumes and quilts.
To interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign InTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign In