cancel
Showing results for 
Search instead for 
Did you mean: 
vattikutiv
Community Participant

How do I access class calendars?

Jump to solution

Hi, I'm trying to make calendar events for a specific course with the python API, but I can't seem to figure out how. Is it even possible?

Can I list events only from that course's calendar as well?

Thanks!

0 Kudos
1 Solution

Accepted Solutions

How can I get only future events from a course calendar?

You should be able to do that by passing an end_date with a future date instead of passing all_events=True.

Something like this:

events = canvas.get_calendar_events(
context_codes=["course_123456"],
end_date="2019-08-13T23:59:59Z"
)‍‍‍‍‍‍‍‍


Note that according to the List calendar events API Docsend_date defaults to the value of start_date, which in turn defaults to the current date.

EDIT: My initial solution did not perform the desired action. I have updated it to work properly.

View solution in original post

0 Kudos
7 Replies
matthew_emond
Community Participant

Hey  @vattikutiv ,

You can absolutely perform these actions with the API!

When you say the Python API, are you referring to UCF's CanvasAPI? If so, here are some code snippets that should help you get started:

I'm trying to make calendar events for a specific course

That should be possible by using create_calendar_event(). To make it in a course, you'll need to pass the calendar_event[context_code] parameter in the form of course_<id>

canvas = Canvas(API_URL, API_KEY)

new_event = canvas.create_calendar_event(
calendar_event={
"context_code": "course_123456",
"title": "New Event",
"description": "This is an event that will happen soon.",
"start_at": "2019-07-21T09:00:00Z",
"end_at": "2019-07-21T23:59:59Z",
}
)‍‍‍‍‍‍‍‍‍

Can I list events only from that course's calendar as well?

That should be possible by using get_calendar_events() and passing the context_codes[] parameter in the form of course_<id>. Note that according to the API Documentation for "List calendar events", you must also either set the all_events parameter to True, or fill in start_dateend_date, and/or undated to get a response.

canvas = Canvas(API_URL, API_KEY)

events = canvas.get_calendar_events(
context_codes=['course_123456'],
all_events=True
)

for event in events:
print(event)


Hopefully that does what you need. Please let me know if that works for you or if you have any other questions! You can also join our UCF open source Slack channel for more direct discussion.

Happy coding!

This was it! Thank you for posting that code.

One more request: How can I get only future events from a course calendar?

How can I get only future events from a course calendar?

You should be able to do that by passing an end_date with a future date instead of passing all_events=True.

Something like this:

events = canvas.get_calendar_events(
context_codes=["course_123456"],
end_date="2019-08-13T23:59:59Z"
)‍‍‍‍‍‍‍‍


Note that according to the List calendar events API Docsend_date defaults to the value of start_date, which in turn defaults to the current date.

EDIT: My initial solution did not perform the desired action. I have updated it to work properly.

View solution in original post

0 Kudos

Thank you once again!

Sure thing! If you have any other questions, please let me know.

Also, the best way to get help for the library is the Slack channel I linked above, so feel free to come say hello!

vattikutiv
Community Participant

 @matthew_emond  I did check out the slack channel-- 

I asked a question there, but I don't know where you'll reply faster so I'm asking it here as well:

The start_date is not returning all the events past today, but is only giving me today's events. If I change it to tomorrow, it will only print tomorrow's date. Can there be a problem with the code that you gave me?

We solved your issue in the Slack channel, but I have also edited my previous response above to a proper solution.