REGISTER NOW: Supercharge Your Cloud Integrations and Watch Our Webinar Recording

Kloudless Blog

Tutorials, case studies and how-tos from our experts

Finding a time to meet via the Google Calendar API

In any organization, users commonly need to see when others are available to meet on a given day, or over a certain time period. This information helps schedule meetings, and also book resources such as rooms or equipment. Our own organization uses Google Calendar for this purpose, as shown below.

Apps integrating with Google Calendar often have similar needs for this data. The naive way to retrieve this meeting data via the API would be to fetch all the events in a user’s calendar(s), resolve overlapping ones, and use it to determine available times. However, this approach is more complex than it needs to be.

Fortunately, Google Calendar provides an API endpoint (docs) to retrieve free/busy information within a calendar account. “free/busy” data represents the times a user’s calendar indicates the user is “busy”, and implies when they’re “free”. In this blog post, we’ll describe how to use this API endpoint to duplicate the data Google Calendar displays in the screenshot above.

Accessing free/busy data

First, we obtain the list of calendar IDs we’d like to query for availability. Google Calendar’s calendarList endpoint helps with this. Alternatively, Google supports the keyword primary to refer to the currently authenticated user’s primary calendar, and email addresses to refer to other users’ primary calendars.

With the calendar IDs, applications can query for each other’s availability within a certain time range:

The response contains a list of time ranges during which each calendar is busy:

Notice how the time ranges in the response are in UTC. If you’d like them in the user’s time zone instead, such as PST based on the request in this case, add in "timeZone": "-0800" to the request object. Also notice that the room resource itself is represented by a calendar. This simplifies handling resources such as rooms.

The data above represents the meetings in each calendar. Apps can use it to determine non-overlapping time ranges during which all meeting participants and resources such as conference rooms are available.

The Google Calendar API endpoint above also supports Google Group identifiers instead of individual calendar IDs. This is very helpful when scheduling an event that includes all the members in a Google Group or mailing list.

Benefits of the Kloudless API

In the overview above, all calendars are always accessible via a single individual’s account. This may be true within organizations, but it isn’t the case when interacting with external users. Check out the Kloudless Availability API to query calendar availability across multiple different calendar accounts with a single implementation.

The Availability API also allows more detailed queries that return time slots ready to book rather than only times individual users are busy. This lets apps that use Kloudless avoid additional calculation on the client-side. Apps can also use our open-source Meeting Scheduler to coordinate meetings between an app’s users.

Published By

Vinod Chandru