Error Creating Calendar Events through API

Jump to solution
dabaker
Community Novice

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
Community Novice
Author

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