Get the list of created Google Calendar events for a specific user

Viewed 580

I was trying to get the number of events that a specific user created in the past month using Google Calendar API.

The problem is that I got all the events where a user was invited. I don't see how to query only the events that user created.

calendarId: user's email adress updatedMin : today - one month

I am using Google's api explorer to query Calendar API.

2 Answers

Include a query parameter in your request:

q: organizer==user@domain.com

This will filter to only events organized by user@domain.com.

Updated:
Unfortunately the query parameter does not accept key value pairs. This solution will not work.

You can filter them by creator.email or organizer.email

Code:

function getCreatedEvents() {
  var user = 'user@domain.com';
  var today = new Date();
  var date = new Date();
  date.setMonth(date.getMonth() - 1);
  
  var args = {
    timeMin: new Date(date.getTime()).toISOString(),
    timeMax: new Date(today.getTime()).toISOString()
  }
  var events = Calendar.Events.list(user, args).items;

  events.forEach(function (event){
    if(event.creator && event.creator.email == user){
      // do something to events
      Logger.log(event);
    }
  });
}

Output:

output

References:

Related