Deleting events in Google Calander API

Solution 1:

To delete an event just call the delete method. The following code can be found on the Node.js GitHub repo for the Google API

  delete: function (params, callback) {
  var parameters = {
    options: {
      url: 'https://www.googleapis.com/calendar/v3/users/me/calendarList/{calendarId}',
      method: 'DELETE'
    },
    params: params,
    requiredParams: ['calendarId'],
    pathParams: ['calendarId'],
    context: self
  };

  return createAPIRequest(parameters, callback);
}

From : https://github.com/google/google-api-nodejs-client/blob/b08ce4189e6b2efdc7cf3e7c3bdb3cbabb08da8c/apis/calendar/v3.js

If you wanted it as a function:

First get the eventId of the event you want to delete then call the method below with that eventId

function deleteEvent(eventId) {

      var params = {
        calendarId: 'primary',
        eventId: eventId,
      };

      calendar.events.delete(params, function(err) {
        if (err) {
          console.log('The API returned an error: ' + err);
          return;
        }
        console.log('Event deleted.');
      });
    }

Solution 2:

I hope it helps someone with the same problem/question.

function deleteEvent(event_id) {
    gapi.client.load('calendar', 'v3', function() {
        var request = gapi.client.calendar.events.delete({
            'calendarId': 'xxxxxxxxxxxxxxx',
            'eventId': event_id
        });
        request.execute(function(response) {
            if(response.error || response == false){
                alert('Error');
            }
            else{
                alert('Success');               
            }
        });
    });
}