cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
dabaker
New Member

Error Creating Calendar Events through API

Jump to solution

We would like to push our academic calendar from our website's iCalendar file into canvas using the API. I've been successful in getting events and deleting events using the API, but I'm running into issues when trying to create new events. I'm using a PowerShell script to automate the process. My request to create an event is formed as follows:

Invoke-RestMethod -Uri https://milligan.instructure.com/api/v1/calendar_events.json  -Method POST -H $headers -Body $json

My headers are OK since they're the same as I've used for getting and deleting calendar events. It seems there is something wrong with the URL.

Here is my JSON object (the $json variable):

{

    "calendar_event[start_at]":  "2016-07-19T21:00:00Z",

    "calendar_event[title]":  "Test Event",

    "calendar_event[end_at]":  "2016-07-19T22:00:00Z",

    "calendar_event[context_code]":  "course_348"

}

I receive the following error when making this request:

{"errors":[{"message":"The specified resource does not exist."}],"error_report_id":492649}

Anybody have any success using the API for creating calendar events? If so, how were your requests formatted? I thought I was matching what was in the API documentation but could be missing something. Any ideas what I might have wrong? Thanks for any help.

David

1 Solution
dabaker
New Member

Answered in Google Groups

<hr>

Graham - thanks for that info! That seems to have done it! I thought I had tried that, but I think I was leaving off the calendar_event[] part of each field parameter.

For reference, here's my request URL:

https://myinstitution.instructure.com/api/v1/calendar_events?calendar_event[context_code]=course_348... Event&calendar_event[start_at]=2016-07-25T21:00:00Z
David


On Wednesday, June 22, 2016 at 10:43:12 AM UTC-4, Graham Ballantyne wrote:

Hi David,

According to the API docs for Calendar Events, that endpoint is expecting form-encoded data, not JSON:

curl 'https://<canvas>/api/v1/calendar_events.json' \ -X POST \ -F 'calendar_event[context_code]=course_123' \ -F 'calendar_event[title]=Paintball Fight!' \ -F 'calendar_event[start_at]=2012-07-19T21:00:00Z' \ -F 'calendar_event[end_at]=2012-07-19T22:00:00Z' \ -H "Authorization: Bearer <token>"

Try sending the data as form-encoded data in the POST body and see what happens.

View solution in original post

2 Replies
dabaker
New Member

Answered in Google Groups

<hr>

Graham - thanks for that info! That seems to have done it! I thought I had tried that, but I think I was leaving off the calendar_event[] part of each field parameter.

For reference, here's my request URL:

https://myinstitution.instructure.com/api/v1/calendar_events?calendar_event[context_code]=course_348... Event&calendar_event[start_at]=2016-07-25T21:00:00Z
David


On Wednesday, June 22, 2016 at 10:43:12 AM UTC-4, Graham Ballantyne wrote:

Hi David,

According to the API docs for Calendar Events, that endpoint is expecting form-encoded data, not JSON:

curl 'https://<canvas>/api/v1/calendar_events.json' \ -X POST \ -F 'calendar_event[context_code]=course_123' \ -F 'calendar_event[title]=Paintball Fight!' \ -F 'calendar_event[start_at]=2012-07-19T21:00:00Z' \ -F 'calendar_event[end_at]=2012-07-19T22:00:00Z' \ -H "Authorization: Bearer <token>"

Try sending the data as form-encoded data in the POST body and see what happens.

m_a_r_scolding
New Member

Hi

I finally found the correct JSON format for creating/editing a calendar event :

{
"calendar_event":
 {
  "context_code": "group_2919",
  "title": "Party",
  "description": "Shindig",
  "start_at": "2019-03-04T12:00:00Z",
  "end_at": "2019-03-04T13:00:00Z",
  "location_name": "Martin's House",
  "all_day": "false"
 }
}

This adds the event to the pre-existing group with ID = 2919.

I've managed to sync our teaching sessions (lectures, seminars, workshops...) from our SRS into Canvas via the API.  Students have membership of groups via SIS Import of group_categories.csv, groups.csv and groups_membership.csv.  The group id can be retrieved using the Groups API.

What I didn't realise is that students in groups can edit/delete the group calendar events I've created via their calendar, which is not what we want!

Martin