23
votes

So I've been using the REST method of invoking Google's API. I need to insert events into a particular calendar whose ID I have. This is the POST request I'm sending:

Address: https://www.googleapis.com/calendar/v3/calendars/{calendarID}/events

Body:

Authorization:  Bearer {access_token}
{
 "end": {
  "dateTime": "2012-08-30T12:30:00",
  "timeZone": "America/Chicago"
 },
 "start": {
  "dateTime": "2012-08-30T14:00:00",
  "timeZone": "America/Chicago"
 },
 "summary": "E E 306",
 "colorId": "9"
 "kind": "calendar#event"
}

And this is the response I keep getting:

{
 "error":{
  "errors":[
   {
    "domain":"calendar",
    "reason":"timeRangeEmpty",
    "message":"The specified time range is empty.",
    "locationType":"parameter",
    "location":"timeMax"
   }
  ],
  "code":400,
  "message":"The specified time range is empty."
 }
}

I don't understand what I could possibly be doing wrong. I've entered all necessary data, and it's asking me for a parameter that doesn't even exist for events. I also can't find any documentation out there on this particular problem. Does anyone see something I'm missing?

5
FYI you may want to edit out your access token, and try to avoid making it public in the future. Even though they expire after an hour, someone could use that token to read from and potentially write to your calendar while it's still valid.Jason Hall
Oops, I suppose that's true. How long do those things last again?AnonymousJohn

5 Answers

61
votes

In the midst of asking this question, I face palmed so hard I think I've done myself brain damage. As it turns out, the reason I couldn't find any documentation on this problem was because of how spectacularly silly it was.

The reason it was giving me such a funny error was because in the copy-pasting I was doing to test, I flipped the start and end times. So, I was telling Google Calendars to enter an event that ended before it started, which generally doesn't end too well.

Long story short, if you get an error referring to the "timeMax" parameter while trying to insert an event, check your start and end times.

1
votes
{
 "end": {
  "dateTime": "2014-04-01T10:00:00-06:00"
 },
 "start": {
  "dateTime": "2014-04-02T10:00:00-06:00"
 }
1
votes

Compare the start and end dateTime, start is always less than end. Also change dateTime format as "2018-03-07T18:00:00+05:30".

In IOS, I use

this code for dateTime format:

let dateTimeFormatter = DateFormatter()
dateTimeFormatter = Locale(identifier: "en_US_POSIX")
dateTimeFormatter = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
dateTimeFormatter = TimeZone(secondsFromGMT: 0)
let dateTimeString = dateTimeFormatter.string(from: YOUR_DATE_TIME)

this code for date format:

let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"
let dateString = dateFormatter.string(from: YOUR_DATE)

One key and it's value is enough, remaining two keys no need i.e., you have 'dateTime' key with value, then is there no need for 'date' and 'timeZone' keys. If you want to set 'timeZone' it's optional, but only one from 'date' and 'dateTime' is enough.

0
votes

Mostly this issue is encountered when start > end

Example: You're specifying Start and End Date as follows:

Start: 2020-10-10T13:30:00+5:30 (i.e. 10th Oct 2020 @1:30PM) End: 2020-10-10T13:00:00+5:30 (i.e. 10th Oct 2020 @1:00PM)

End Time Should be Greater than the start Time.

{
"summary": "some summary",
"description": "some description",
"location": "some location",
"end":  {"dateTime" : "2020-10-10T13:30:00+5:30"},
"start" : { "dateTime" : "2020-10-10T13:00:00+5:30"},
}