1
votes

I have the following JSON

var resource = {
  "summary": "Sample Event",
  "start": {
    "dateTime": sample1
  },
  "end": {
    "dateTime": twoHoursLater
  },
  "reminders": {
    "useDefault": false,
    "overrides": [
      {
        "method": "popup",
        "minutes": "5"
      },
      {
        "method": "email",
        "minutes": "5"
      }

    ]
  }
};

I can insert it to Google Calendar using the code below

function addEvent() {
  gapi.client.load('calendar', 'v3', function() {
    var request = gapi.client.calendar.events.insert({
      'calendarId':   calendarId,
      'resource':     resource
    });
    request.execute(function(resp) {
      console.log(resp);
    });
  });
}

In Google Calendar website it appears as:

5 minutes before, as email
5 minutes before

As you can see the event the I have has reminders, meaning it will notify via Popup and Email, 5 minutes before the event starts.

Now, the thing is I want to remove this event reminder programatically using the API.

What I have tried so far:

Test 1:

Based on the documentation https://developers.google.com/calendar/concepts/reminders

It says "To revert back to the default set of reminders, perform an update setting reminders.useDefault back to true."

var resource3 = {
  "summary": "Sample Event xx",
  "start": {
    "dateTime": sample1
  },
  "end": {
    "dateTime": twoHoursLater
  },
  "reminders": {
    "useDefault": true
  }
};

function updateEvent(eventId) {
  gapi.client.load('calendar', 'v3', function() {
    var request = gapi.client.calendar.events.patch({
      'calendarId':   calendarId,
      'eventId':     eventId,
      'resource':     resource3
    });
    request.execute(function(resp) {
      console.log(resp);
    });
  });
}

The code above will return an error Cannot specify both default reminders and overrides at the same time. in the console.

Test 2:

Based on an accepted answer on stackoverflow Google Calendar API: How to disable Notifications?

It says "Therefore I think you can just set "useDefault": false and don't supply any overrides, and it should result in the event having no reminders."

var resource3 = {
  "summary": "Sample Event xx",
  "start": {
    "dateTime": sample1
  },
  "end": {
    "dateTime": twoHoursLater
  },
  "reminders": {
    "useDefault": false
  }
};

function updateEvent(eventId) {
  gapi.client.load('calendar', 'v3', function() {
    var request = gapi.client.calendar.events.patch({
      'calendarId':   calendarId,
      'eventId':     eventId,
      'resource':     resource3
    });
    request.execute(function(resp) {
      console.log(resp);
    });
  });
}

The patching/updating works on other fields such as summary, start, and end. But it does not remove the event reminder.

Test 3:

This is what I have experimented on so far. I removed the reminders completely. Still no luck. Same output as in Test 2.

var resource3 = {
  "summary": "Sample Event xx",
  "start": {
    "dateTime": sample1
  },
  "end": {
    "dateTime": twoHoursLater
  }
};

unction updateEvent(eventId) {
  gapi.client.load('calendar', 'v3', function() {
    var request = gapi.client.calendar.events.patch({
      'calendarId':   calendarId,
      'eventId':     eventId,
      'resource':     resource3
    });
    request.execute(function(resp) {
      console.log(resp);
    });
  });
}

Do you have any idea on how to remove the event reminder?

4

4 Answers

1
votes

So after working around with it, I successfully removed the event notification using the API. The answer is almost close as stated in Test 2 and it is done by using the code below:

var resource3 = {
  "summary": "Sample Event xx",
  "start": {
    "dateTime": sample1
  },
  "end": {
    "dateTime": twoHoursLater
  },
  "reminders": {
    "useDefault": false,
    "overrides": []
  }
};

function updateEvent(eventId) {
  gapi.client.load('calendar', 'v3', function() {
    var request = gapi.client.calendar.events.patch({
      'calendarId':   calendarId,
      'eventId':     eventId,
      'resource':     resource3
    });
    request.execute(function(resp) {
      console.log(resp);
    });
  });
}

I just need to add the overrides and giving it an empty value. I hope this helps if you encountered the same question.

0
votes

When patching using the libraries you can't just set overrides to null, you need to use Data.nullOf(ArrayList.class):

 Event.Reminders reminders = new Event.Reminders()
                        .setUseDefault(false)
                        .setOverrides(Data.nullOf(ArrayList.class));
                newEvent.setReminders(reminders);
0
votes

In my experience, patch/update for the event following the

reminders: {
  useDefault: false,
  overrides: []
}

only worked for Firefox, while Chrome kept stubbornly holding onto the defaults. (It was super baffling, I checked it several times: the same event would have different reminders when viewing it in Firefox vs Chrome.)

The way I got around it was by not creating the events in the first place, using the Calendar API:

const event = {
  start: {...},
  end: {...},
  summary: 'My Event',
  reminders: {
    useDefault: false
  }
}
Calendar.Events.insert(event, calendarId)

This means I couldn't use the (slightly easier) Calendar service provided by Google in the app scripts but hey the API isn't too bad either.

-1
votes

Try this:

var resource3 = {
  "summary": "Sample Event xx",
  "start": {
    "dateTime": sample1
  },
  "end": {
    "dateTime": twoHoursLater
  },
  "reminders": {
    "useDefault": false,
    "overrides": []
  }
};

function updateEvent(eventId) {
  gapi.client.load('calendar', 'v3', function() {
    var request = gapi.client.calendar.events.patch({
      'calendarId':   calendarId,
      'eventId':     eventId,
      'resource':     resource3
    });
    request.execute(function(resp) {
      console.log(resp);
    });
  });
}