27

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?

2
  • 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. Commented Jun 5, 2012 at 4:33
  • Oops, I suppose that's true. How long do those things last again? Commented Jun 7, 2012 at 0:55

5 Answers 5

73

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.

Sign up to request clarification or add additional context in comments.

5 Comments

I also made a similar mistake. Thanks for the explanation.
Same here hahaha. This solved it. Plenty of room in SO for silly gotchas. They really need a better error message like: "start date cannot be after end date."
Still the error message should be improved by Google, it can be confusing if you're using timeMin timeMax to retrieve events prior to inserting new ones.
Basically, either "Startdate/StartDateTime" should always before "Enddate/EnddateTime"
same here :| i guess to much time working
1

The dateTimes must be on RFC3339 as described here:

https://developers.google.com/google-apps/calendar/v3/reference/events

Comments

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

Comments

1

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.

Comments

1

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"},
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.