Removing event notifications with Google Calendar API v3 (JavaScript): A Step-by-Step Guide

After creating a JSON object with event details, I attempted to add it to Google Calendar using the provided code snippet:

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);
    });
  });
}

Upon submitting the event, reminders were set for 5 minutes before via Popup and Email. Now, I am looking for a way to remove these reminders programmatically through the API.

Efforts Made So Far:

Attempt 1:

Following official documentation guidelines stated on this link, I tried setting reminders.useDefault back to true. However, this resulted in an error:

Cannot specify both default reminders and overrides at the same time.

Attempt 2:

Based on suggestions from a StackOverflow post (link here), I set "useDefault": false without any overrides in the code. Unfortunately, this did not remove the reminders as expected.

Attempt 3:

In another trial, I completely removed the reminders section from the JSON object but faced similar results to Attempt 2.

If you have insights or suggestions on how to successfully remove the event reminder, your input would be highly appreciated.

Answer №1

After some tinkering, I managed to successfully eliminate the event notification using the API. The solution closely resembles what was mentioned in Test 2, achieved by implementing the following code:

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);
    });
  });
}

All that was needed was to include the overrides and assign it an empty value. If you face a similar issue, hopefully this solution proves helpful.

Answer №2

When making updates with the libraries, it's important to remember that simply setting overrides to null won't work - you should instead utilize Data.nullOf(ArrayList.class):

 Event.Notifications notifications = new Event.Notifications()
                        .setDefaultSetting(false)
                        .setCustomNotifications(Data.nullOf(ArrayList.class));
                updatedEvent.setNotifications(notifications);

Answer №3

In my personal experience, I found that when dealing with patch/update for the event right after the reminders:

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

it seemed to work smoothly in Firefox, but Chrome was a bit more stubborn and held onto the default settings. It was quite puzzling because I noticed that the same event would display different reminders depending on whether I viewed it in Firefox or Chrome.

To overcome this issue, I opted not to create the events initially and instead utilized the Calendar API:

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

This meant I couldn't leverage the (slightly simpler) Google-provided Calendar service in app scripts, but working with the API wasn't too cumbersome either.

Answer №4

Give this a shot:

let newEvent = {
  "summary": "New Sample Event",
  "start": {
    "dateTime": sampleTime
  },
  "end": {
    "dateTime": laterByTwoHours
  },
  "reminders": {
    "useDefault": false,
    "overrides": []
  }
};

function modifyEvent(eventIdentifier) {
  gapi.client.load('calendar', 'v3', function() {
    let request = gapi.client.calendar.events.patch({
      'calendarId':   calendarIdentifier,
      'eventId':     eventIdentifier,
      'resource':     newEvent
    });
    request.execute(function(response) {
      console.log(response);
    });
  });
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Getting Started with Arrays in JavaScript

I've been working on improving my JavaScript skills but I seem to have hit a roadblock. var schemes = { "own" : { "creatures" : ["creature1","creature2","creature3","creature4"], "spells" : ["spell1","spell2","spell3","spell4"], ...

Guide to making a 'Put' request using a JSON object towards a JSONPlaceHolder RESTful API in Java

I have a piece of code that retrieves all the data from the JSONPlaceHolder REST API and converts it into an array. Afterwards, I collect input from text fields in my program to create a JSON Object with that information. Now, I want to send this JSON Obje ...

Ways to update the div's appearance depending on the current website's domain

There is a piece of code that is shared between two websites, referred to as www.firstsite.com and www.secondsite.com The goal is to conceal a specific div only when the user is on secondsite. The access to the HTML is limited, but there is an option to ...

When working with JSON in Angular, the JSON pipe may display an empty string for values that are "undefined"

When utilizing the json pipe within Angular, it displays a blank for any undefined values. <pre>{{undefined | json}}</pre> The output on the DOM is as follows: <pre></pre> This behavior differs from the JSON stringify function. ...

I am struggling to render the pages and components in React while using BrowserRouter

Below is the code snippet for App.js and Home.js that I'm working on. My aim is to showcase the Home.js component in the browser. App.js import "./App.css"; import { Route, BrowserRouter } from "react-router-dom"; import Home from ...

Avoiding repetitive clicking of buttons in jQuery—strategies for success

Hello, I am currently facing an issue where I need to reset the content of a div using an AJAX call when a user clicks a button. However, if the user clicks multiple times in quick succession, an error occurs. I would like to find a way to prevent users fr ...

Public directory assets not accessible

After working extensively with Node and Angular, I realized my back-end structure needed some serious attention. In an effort to streamline my process, I decided to separate the client and server components and create a reusable skeleton for future applica ...

Utilizing Smarty to Retrieve JavaScript Variables from Database Entries

Currently, I am working on a PrestaShop page that uses the file extension ".tpl". To enable auto complete for the javascript code, I have defined an array of currencies as shown below: var currencies = [ { value: 'Afghan afghani', data: 'AF ...

Using for loops in Vue.js to dynamically generate HTML elements

I have a JSON object passed into an EJS template, and I want to achieve the same table structure in VUE.js. However, it seems like v-for in Vue only works with li tags. Is there a way to create a similar loop in VUE that generates HTML elements like show ...

choose among various options in Javascript

I'm currently using PHP and AJAX to create a basic CRUD system. I want to display a form with three buttons: Grabar, Modificar, and Eliminar. The issue I'm facing is determining the action to take based on which button is clicked. For instance, c ...

Retrieving key-value pairs from an array of JSON objects

How can I access key-value pairs in JavaScript if the JSON file is formatted like this: [[{"field":"name","message":"Insert name!"},{"field":"surname","message":"Insert surname!"},{"field":"email","message":"Insert email"}]]; The current solution seems ...

How can I make a Three.js Physijs mesh move towards the mouse?

After browsing through various posts and documentation, I am trying to figure out how to make a BoxMesh follow the mouse cursor. My ultimate goal is to implement joystick touch controls for games like Heroes of Loot. For now, I am focusing on getting direc ...

What sets apart +variable+ and ${variable} in JavaScript?

Just starting to code and eager to learn. While I was taking in a lecture, I came across this interesting snippet of code: var coworkers = ['go', 'hello', 'hi', 'doit']; <script type="text/javascript&q ...

"Utilize the UpdateOne function in MongoDB to add a value from a different field

Attempting to add an existing field of my document to an array. Here is the schema: const mySchema = new Schema({ level: { type: Number, default: 1 }, mHierarchy: [ { userId: { type: mongoose. ...

The connection was forcibly rejected when trying to send a proxy request from one local server to another on

As a newcomer to Angular, I have been following a tutorial video step by step, but I've hit a roadblock that I've been trying to resolve for nearly two weeks. Despite spending numerous hours searching through forums for solutions, I have not been ...

Incorporating Jquery element loading animation for enhanced webpage experience

Currently, I am involved in a project where I aim to incorporate a fade effect on an element within the webpage. Upon loading the page, these elements are intended to appear with a subtle fade-in effect. Although attempting a basic method in jQuery such ...

Creating an associative array in Javascript by utilizing a for loop

I am attempting to create an array called userRow{} by using: $('#divResults tr').find('td:nth-child(2)').text(); This will fetch 12 first names from a column in an HTML table, such as John, Dave, and so on. $('#divResults tr&ap ...

Is it possible for you to provide both a status code and an HTML webpage?

I've been working with the express framework in node, but I'm unsure if what I'm doing is best practice. I want to send a specific status code such as res.status(200).send("Success"); when the form input matches the server, and another statu ...

Creating a customizable HTML template for JSON data representation

I have incorporated t.js as the template engine in my current project. How can I create a template for this specific JSON data structure? { data: [ { FirstName: "Test1", LastName: "Test11" }, { FirstName: "Test2", ...

Search functionality that dynamically updates results as the user types, thanks

I am currently working on implementing a search feature that can assist users when typing in their search queries. The goal is to use Ajax to dynamically show results as the user types. Currently, the functionality requires the user to hit the search butt ...