Daniyal dehleh
Daniyal dehleh

Reputation: 2382

Google Calendar FreeBusy API not showing empty time slots

I have events from:

I am trying to get all the empty calendar slots in within the timeMin and timeMax duration.

Yet when I do at freebusy API:

{
  "timeMin": "2021-03-25T11:42:20.698908-04:00",
  "timeMax": "2021-03-25T22:42:20.698908-04:00",
  "calendarExpansionMax": 10 #doesn't make any difference
}

I get:

{
 "kind": "calendar#freeBusy",
 "timeMin": "2021-03-25T15:42:20.000Z",
 "timeMax": "2021-03-26T02:42:20.000Z"
}

which I don't know what it even represents nor does it make it clear. I am not sure why it's even going post the timeMax duration I allowed by going to the next day (26th).

If the freebusy api isn't the solution, has anyone built a solution for it in python, as there are many SO answers and libs for javascript.

Upvotes: 1

Views: 1172

Answers (1)

Nikko J.
Nikko J.

Reputation: 5533

You have missing parameter item[] in your request. This is where you put the calendar id which the request will do its query.

Your request parameter should look like this:

{
  "timeMin": "2021-03-25T11:42:20.698908-04:00",
  "timeMax": "2021-03-25T22:42:20.698908-04:00",
  "timeZone": "UTC-4",
  "items": [
    {
      "id": "insert the calendar id here"
    }
  ]
}

Output:

{
 "kind": "calendar#freeBusy",
 "timeMin": "2021-03-25T03:42:20.000Z",
 "timeMax": "2021-03-25T14:42:20.000Z",
 "calendars": {
  "calendar id here": {
   "busy": [
    {
     "start": "2021-03-25T11:42:20+08:00",
     "end": "2021-03-25T13:30:00+08:00"
    },
    {
     "start": "2021-03-25T15:45:00+08:00",
     "end": "2021-03-25T17:45:00+08:00"
    },
    {
     "start": "2021-03-25T19:00:00+08:00",
     "end": "2021-03-25T22:42:20+08:00"
    }
   ]
  }
 }
}

Since it only return the busy time range, you have to calculate the free time in your script.

Upvotes: 3

Related Questions