Search code examples
reactjsgmailgoogle-calendar-api

Google Calendar Event Notifications are not coming in gmail's of attendees


I am using google calender api for inserting event in google calender & its also adding in attendess google calender but problem is that notification of event creation is not showing in attendees & also in owner account.

I am using react as frontend.

Anykind of help or sharing is most appreciated.

My code:-

function addManualEvent(){
    var event = {
      'kind': 'calendar#event',
      'summary': 'Last Event 9',
      'location': 'Masai School, Bangalore',
      'description': 'Paty time',
      'start': {
        'dateTime': '2023-03-17T14:36:00.000Z',
        'timeZone': 'UTC'
      },
      'end': {
        'dateTime': '2023-03-17T14:37:00.000Z',
        'timeZone': 'UTC'
      },
      'recurrence': [
        'RRULE:FREQ=DAILY;COUNT=1'
      ],
      'attendees': [
        {'email': 'sureshsingh11661@gmail.com','responseStatus':'needsAction'},
        {'email': 'ritiksingh11661@gmail.com','responseStatus':'needsAction'}
      ],
      'reminders': {
        'useDefault': true,
      },
      "guestsCanSeeOtherGuests": true,
      'sendUpdates': 'all'
    }
      var request = gapi.client.calendar.events.insert({'calendarId': 'primary','resource': event});
      request.execute(function(event) {
          console.log(event)
          window.open(event.htmlLink)
      },function(error) {
        console.error(error);
      });
  }

I want notification of event in owner & also attendees's gmail.


Solution

  • The problem is that you're adding 'sendUpdates': 'all' as part of your event object and it doesn't go there. The sendUpdates parameter is part of the query parameters. If you check out the documentation for events.insert you'll see that sendUpdates is in the parameters section, not in the request body.

    To correct this, add sendUpdates in your gapi.client.calendar.events.insert call. Make sure to also remove it from your event variable:

    var request = gapi.client.calendar.events.insert({
          "calendarId": "primary",
          "sendUpdates": "all",
          "resource": event
          })
    

    Reference