Deepak Kumbhar
Deepak Kumbhar

Reputation: 534

Google calendar event API date filter is not working

I am using google calendar API to fetch the event lists. What I am doing over here is I am adding filter to get event of specific date, so for that I have used timeMin and timeMax keys. But this filter is not working at all. It is giving me results of other dates as well. Can someone please help me with what am I doing wrong?

Here is my request URL.

https://www.googleapis.com/calendar/v3/calendars/EMAIL/events?key=KEY&timeMin=2021-07-15T00:00:00.000Z&timeMax=2021-07-17T00:00:00.000Z&timeZone=Asia/Calcutta

Thanks in advance!

Upvotes: 0

Views: 1345

Answers (1)

ziganotschka
ziganotschka

Reputation: 26806

The timeMin and timeMax parameters are confusing and do not correspond to the Date options from...to of the UI search

As per documentation:

timeMax: Upper bound (exclusive) for an event's start time to filter by.

timeMin: Lower bound (exclusive) for an event's end time to filter by.

In other words, defining

timeMin=2021-07-15T00:00:00.000Z&timeMax=2021-07-17T00:00:00.000Z

will return you all events that started before 2021-07-17T00:00:00.000Z and end after 2021-07-17T00:00:00.000Z.

You need to modify the query and look for event on the date indirectly by e.g. looking for events that started before 2021-07-17T23:59:59.999Z and ended after 2021-07-17T00:00:00.000Z.

Thereby, make sure to set singleEvents to true to exlucde event series (recurring events).

Once you have a list of candidates, you might still need to query for the start and end properties of the event resource and filter out the spare results.

Upvotes: 2

Related Questions