Your Community is getting an upgrade!
Read about our partnership with Higher Logic and how we will build the next generation of the Instructure Community.
Found this content helpful? Log in or sign up to leave a like!
I am making reference to the Calendar Events API. As an Instructor, I am trying insert a class timetable to a section with what I believe to be the correct JSON but I get a 500 error response. I've tried to look at the API Ruby code to work out where my mistake lies but can't seem to spot anything.
I am calling `url:POST|/api/v1/courses/:course_id/calendar_events/timetable_events`
I am sending it this JSON:
{"course_section_id": "73842", "events[]": [{"events[][start_at]": "2023-06-30T09:00:00Z", "events[][end_at]": "2023-06-30T10:00:00Z", "events[][location_name]": "Applied Science Building - East Lecture Theatre", "events[][code]": "Fri09:00-10:00"}, {"events[][start_at": "2023-06-30T10:00:00Z", "events[][end_at]": "2023-06-30T12:00:00Z", "events[][location_name]": "DAIM Level 1 Ground Floor", "events[][code]": "Fri10:00-12:00"}, {"events[][start_at]": "2023-06-30T09:00:00Z", "events[][end_at]": "2023-06-30T12:00:00Z", "events[][location_name]": "DAIM Level 1 Ground Floor", "events[][code]": "Fri09:00-12:00"}]}
However I get back this:
{"errors":[{"message":"An error occurred.","error_code":"internal_server_error"}],"error_report_id":3874035}
I am able to set a single timetable event, but not able to set a list of events. I also tried using the URL
url:POST|/api/v1/courses/:course_id/calendar_events/timetable but was not ale to get that to accept lists of start times on different days.
Can anyone point out my obvious error? (This was coded from Python)
Solved! Go to Solution.
The examples in the documentation are not JSON and when you send it as JSON, you need to reorganize it into an object. You are mixing the two formats together and that's generating the error.
You don't repeat the outer levels and the brackets around the property names just become properties.
It should look more like this.
{
"course_section_id": "73842",
"events": [
{
"start_at": "2023-06-30T09:00:00Z",
"end_at": "2023-06-30T10:00:00Z",
"location_name": "Applied Science Building - East Lecture Theatre",
"code": "Fri09:00-10:00"
},
{
"start_at": "2023-06-30T10:00:00Z",
"end_at": "2023-06-30T12:00:00Z",
"location_name": "DAIM Level 1 Ground Floor",
"code": "Fri10:00-12:00"
},
{
"start_at": "2023-06-30T09:00:00Z",
"end_at": "2023-06-30T12:00:00Z",
"location_name": "DAIM Level 1 Ground Floor",
"code": "Fri09:00-12:00"
}
]
}
Here's a helpful hint: If you expand the editor toolbar, there is a source </> button that allows you to enter code. JSON isn't an option, so I used JavaScript.
Update: I originally had events[] and it did not work. Removing the [] after events makes it work. Some API calls need the [] to indicate multiple values are allowed and I wasn't sure. I have now tested the above to make sure it works.
The examples in the documentation are not JSON and when you send it as JSON, you need to reorganize it into an object. You are mixing the two formats together and that's generating the error.
You don't repeat the outer levels and the brackets around the property names just become properties.
It should look more like this.
{
"course_section_id": "73842",
"events": [
{
"start_at": "2023-06-30T09:00:00Z",
"end_at": "2023-06-30T10:00:00Z",
"location_name": "Applied Science Building - East Lecture Theatre",
"code": "Fri09:00-10:00"
},
{
"start_at": "2023-06-30T10:00:00Z",
"end_at": "2023-06-30T12:00:00Z",
"location_name": "DAIM Level 1 Ground Floor",
"code": "Fri10:00-12:00"
},
{
"start_at": "2023-06-30T09:00:00Z",
"end_at": "2023-06-30T12:00:00Z",
"location_name": "DAIM Level 1 Ground Floor",
"code": "Fri09:00-12:00"
}
]
}
Here's a helpful hint: If you expand the editor toolbar, there is a source </> button that allows you to enter code. JSON isn't an option, so I used JavaScript.
Update: I originally had events[] and it did not work. Removing the [] after events makes it work. Some API calls need the [] to indicate multiple values are allowed and I wasn't sure. I have now tested the above to make sure it works.
Thank you for the reply. I had tried various combinations of syntax thinking it was something like that! However I just tried again with your suggestion and still get the same 500 error. The JSON sent is shown below, which on the surface looks just like your suggestion. I'm now wondering if the overlapping times are causing a problem, or if it is something else.
{
'course_section_id': '73842',
'events[]': [
{
'start_at': '2023-06-30T09:00:00Z',
'end_at': '2023-06-30T10:00:00Z',
'location_name': 'Applied Science Building - East Lecture Theatre',
'code': 'Fri09:00-10:00'
},
{
'start_at': '2023-06-30T10:00:00Z',
'end_at': '2023-06-30T12:00:00Z',
'location_name': 'DAIM Level 1 Ground Floor',
'code': 'Fri10:00-12:00'
},
{
'start_at': '2023-06-30T09:00:00Z',
'end_at': '2023-06-30T12:00:00Z',
'location_name': 'DAIM Level 1 Ground Floor',
'code': 'Fri09:00-12:00'
}
]
}
The snippet you provided isn't valid JSON. JSON uses double quotes, not single quotes.
I wrote the first response without actually testing it and the other question I had at the time was about the [] at the end of events. In some API calls, if you don't include the double brackets at the end it doesn't work. Here, including the [] breaks it and not including it works. If you're not using JSON, you may need to put an index in the brackets so it can distinguish the items.
I took what I originally posted, changed the IDs and sent it to one of my courses. It came back with an internal error. When I sent the same JSON with events rather than events[], it came back with OK and the events were on my calendar.
I'll edit my original response to remove the [] after events in case someone else stumbles across this in the future.
Excellent. It was the [] characters that did the trick!
(The quotes were a python artefact and not included in the JSON I actually sent.)
To interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign InTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign In