Calendar Events API - Setting a section timetable

Jump to solution
b_c_tompsett
Community Member

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)

Labels (1)
0 Likes
1 Solution
James
Community Champion

@b_c_tompsett 

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.

View solution in original post

0 Likes