cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Community Member

Canvas API not returning calendar events.

Jump to solution

Hey guys, I'm working on a project with a friend for fun and we are unable to get calendars to be returned. Am i entering the url incorrectly?

Screen Shot 2016-02-14 at 8.41.41 PM.png

1 Solution

Accepted Solutions
Highlighted
Navigator

Yes, you are entering it incorrectly when you specify both types, but that's not the reason why you're not getting anything.

If you look at the API documentation for the list calendar events, there is an easy to miss note. I wasn't able to get anything until I read it.

context_codes[]

List of context codes of courses/groups/users whose events you want to see. If not specified, defaults to the current user (i.e personal calendar, no course/group events). Limited to 10 context codes, additional ones are ignored. The format of this field is the context type, followed by an underscore, followed by the context id. For example: course_42

If you don't add a context_codes[] to the query, you just get the personal calendar, which for most people is blank.

These don't return anything for me

/api/v1/calendar_events

/api/v1/calendar_events?type=event

/api/v1/calendar_events?context_codes[]=course_1785810

/api/v1/calendar_events?type=assignment&type=event&context_codes[]=course_1785810

/api/v1/calendar_events?all_events=1&type=assignment

These do return results

/api/v1/calendar_events?type=assignment&context_codes[]=course_1785810

/api/v1/calendar_events?type=event&type=assignment&context_codes[]=course_1785810

/api/v1/calendar_events?all_events=1

There are two that look very similar (just the order of type=assignment and type=event) are switched. The type parameter is does not allow multiple entries and it will take whichever one comes last. So, specifying event then assignment is really only specifying assignment and putting assignment followed by event is really just specifying event.

I also couldn't get it to show me any events, even those on my personal calendar, unless I put in all_events=1. But all_events doesn't mean just events, when I include that with type=assignments, it includes all assignments within a context.

If I try to include type=assignment without a context_code, I don't get anything.

Hope that helps.

View solution in original post

5 Replies
Highlighted
Navigator

Yes, you are entering it incorrectly when you specify both types, but that's not the reason why you're not getting anything.

If you look at the API documentation for the list calendar events, there is an easy to miss note. I wasn't able to get anything until I read it.

context_codes[]

List of context codes of courses/groups/users whose events you want to see. If not specified, defaults to the current user (i.e personal calendar, no course/group events). Limited to 10 context codes, additional ones are ignored. The format of this field is the context type, followed by an underscore, followed by the context id. For example: course_42

If you don't add a context_codes[] to the query, you just get the personal calendar, which for most people is blank.

These don't return anything for me

/api/v1/calendar_events

/api/v1/calendar_events?type=event

/api/v1/calendar_events?context_codes[]=course_1785810

/api/v1/calendar_events?type=assignment&type=event&context_codes[]=course_1785810

/api/v1/calendar_events?all_events=1&type=assignment

These do return results

/api/v1/calendar_events?type=assignment&context_codes[]=course_1785810

/api/v1/calendar_events?type=event&type=assignment&context_codes[]=course_1785810

/api/v1/calendar_events?all_events=1

There are two that look very similar (just the order of type=assignment and type=event) are switched. The type parameter is does not allow multiple entries and it will take whichever one comes last. So, specifying event then assignment is really only specifying assignment and putting assignment followed by event is really just specifying event.

I also couldn't get it to show me any events, even those on my personal calendar, unless I put in all_events=1. But all_events doesn't mean just events, when I include that with type=assignments, it includes all assignments within a context.

If I try to include type=assignment without a context_code, I don't get anything.

Hope that helps.

View solution in original post

Highlighted

Hi,

There seem to be some restrictions on accessing calendar data via the API.  I can only get first 10 events/assignments from a calendar.

This is the command I'm using:

/api/v1/calendar_events?all_events=1&type=event&context_codes[]=course_548

Any ideas on why this would be happening or how to work around it?

Thanks in advance for any help.

Highlighted

jvincent@mmiprep.org

That sounds like a pagination issue that is in almost every API call.

The quick fix is add a query_parameter   per_page=100

But there are times when you'll have more than 100, so the real fix is to handle pagination. You can read about it in Pagination - Canvas LMS REST API Documentation

Highlighted

Thank you!  That was my problem.  I'm relatively new to working with API's and pagination had never occurred to me.

Highlighted
Surveyor

From the documentation, for start_date:

Only return events since the start_date (inclusive). Defaults to today

And for end_date:

Only return events before the end_date (inclusive). Defaults to start_date.

So, by default, your calendar_events search will only return events for the current day.

Labels