Showing results for 
Show  only  | Search instead for 
Did you mean: 

Canvas Calendar Institutional Event Creator

Community Contributor
2 1 658


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 = '' # put full canvas prod/test url eg:
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 =

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 =
            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"

finish_timer =
diff = finish_timer - start_timer
puts "Script done running! Took #{diff} seconds to run."








Install Ruby and the following gems - typhoeus, json, and csv.

  1. Copy the script above and create a file in your desired location.
  2. Create calendar_events CSV file and add events.
    1. Column 1 is 'title' of event
    2. Column 2 is 'start date' of event (YYYYMMDD format)
  3. Save file to the same folder as the script file.
  4. Run Provisioning report USERS for term. (We will do this twice as our elementary and secondary terms differ)
  5. Filter csv file for student and teacher users only.
  6. Copy/paste results into new CSV file.
  7. Save file as users.csv in the same folder as the script file.
  8. Remove all columns except Canvas ID column, rename to "id".
  9. Save file.
  10. Update script above with Canvas URL, Canvas Token, file paths for csv_file1 and csv_file2.
  11. Run the script file.

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.


Chad Scott
LMS Support Specialist
Katy ISD Instructional Technology

1 Comment