Showing results for 
Search instead for 
Did you mean: 

Canvas Calendar Show / Hide

Is there a way to push out enabling Calendars for users?  We want our faculty  to use the course calendar and many of them have it hidden and don't even realize it.  I was hoping that there was an API that I could use, and run a script to enable the calendar for all of our faculty for their current term courses.

0 Kudos
5 Replies
Navigator II

This was fun and I learned something new.

There's no endpoint for the calendar to turn them on or off. So, I opened the network tab in Chrome dev tools to see what happens when you click on the calendar button. It shoots a POST request off to an endpoint: 

There's a form attached to the request that has selected_contexts[] field for each course you want activated on the calendar, formatted as course_12345. In the UI, each time you click the checkbox, the form is submitted with each course in an array. Removing a course from the UI removes it from the form submission body.

This works the same for users. Instead of submitting course_12345, submit user_12345 and that will enable (if included) or disable (if not included) their personal calendar on the next page reload.

So, as long as you know the course or user ID, you can set/unset any calendar you want via the API. 


curl --location --request POST '' \
--header 'Authorization: Bearer yourApiKey12345' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'selected_contexts[]=course_12345' \
--data-urlencode 'selected_contexts[]=course_98765'



import requests

url = ""
headers = {
  'Authorization': 'Bearer yourApiKey',
  'Content-Type': 'application/x-www-form-urlencoded'
response = requests.request("POST", url, headers=headers, data=payload)

print(response.text) # { status: ok }

Do you know if there is a GET API that I could use to get the current selected contexts?

This is a mystery. I dug around in the console, the network requests tab in the dev tools, localStorage and sessionStorage, and even how React is populating the page and I can't find where those codes are stored anywhere. They're definitely saved in long term state somehow because the initial request calls the API with each course code directly.

If you want users using all of their calendars, it would probably be safe to do something like this:

  1. Get each user
  2. For each user, get their active courses for the given term (you can get the Term ID in the admin page)
  3. For each course, format it to course_12345 and store in an array
  4. Send the POST request to Canvas, joining each context in the array with some kind of join method (depending on your language of choice).

Thanks, but my goal is to enable specific calendars without disturbing the settings for others.  We are using the Appointment Group APIs in a script to create appointments for classes where some students attend class in person.  Those that attend in person must reserve a slot.  When the limit is reached the rest must attend virtually.  I have had number of instructors using this process that do not have their calendars enabled and I had hoped to make sure that those calendars were enabled for all the instructors involved without disturbing the settings of their other calendars, 

Navigator II

Yeah, I'm not sure there's any way to do that without deeper dives into what session variables Canvas stores for each user. Good luck!