Sending email notifications for Events via Google Calendar API
Asked Answered
B

5

10

I'm using the calendar.events.insert API to add an Event to my Calendar via the PHP client. The event is being inserted correctly along with appropriate values as set by the API. The same however is not able to trigger an email invite to the attendees. I looked around to find that the request needs to set the param sendNotifications as true. The same doesn't seem to help either.

Here is a sample code:

var request = gapi.client.calendar.events.insert({
        "calendarId" : calendarData.id,
        "sendNotifications": true,
        "end": {
          "dateTime": eventData.endTime
        },
        "start": {
          "dateTime": eventData.startTime
        },
        "summary": eventData.eventName, 
        "attendees": jQuery.map(eventData.attendees, function(a) {
          return {'email' : a};
        }),
        "reminders": {
          "useDefault": false,
          "overrides": [
            {
              "method": "email",
              "minutes": 15
            },
            {
              "method": "popup",
              "minutes": 15
            }
          ]
       }
      });

Where eventData and calendarData are appropriate objects.

Although my main problem is with email invites being sent the first time, I also tried (as can be seen above) to set a reminder (using overrides). While the popup works as expected, I didn't receive an email update in this case either.

This makes me wonder whether this may be a permission issue - something which I need to enable for my app perhaps (the user would understandably need to know if my app is sending emails on their behalf)?

Batholith answered 19/11, 2014 at 3:53 Comment(2)
Is it possible that your events are created in the past? For those events no emails are sent.Ballew
Note for everybody coming here late: the parameter to use is now called "sendNotifications" and must be set to "all" in order to send notification to everybody. see documentationLycanthrope
C
6

In the Google API Documentation for inserting events, the "sendNotifications" option is actually a parameter. You might want to put it in the request parameters instead of the body.

In Meteor

Note: In my Meteor application, I did did the request by hand, and I'm still new to JavaScript. I'm not sure how you would do that in plain JavaScript or with the calendar API, so I'll just put the Meteor code, hope it helps although it's a bit off-topic.

var reqUrl = "https://www.googleapis.com/calendar/v3/calendars/primary/events";
var payload = {
  'headers' : {
    'Authorization': "Bearer " + token,
    'Content-Type': 'application/json'
  },
  'params': {
    'sendNotifications': true
  },
  'data': {
    "summary": summary,
    "location": "",
    "start": {
      "dateTime": start
    },
    "end": {
      "dateTime": end
    },
    "attendees": [
      {
        "email": "*********@gmail.com"
      }
    ]
  }
};
Meteor.http.post(reqUrl, reqParams, function () {});
Cytotaxonomy answered 12/3, 2016 at 8:14 Comment(1)
This is the correct answer. Can't add code to a comment, so will create a separate answer with the actual js code.Phrygia
P
4

@linaa is correct. Just ran into this issue myself.

In JS, this would look like:

var request = gapi.client.calendar.events.insert(
    sendNotifications: true,
    {
              // request body goes here
    }
);
Phrygia answered 16/7, 2016 at 9:36 Comment(0)
D
3
event = service.events().insert(calendarId='primary', body=event, sendUpdates='all').execute()

this will work

Davita answered 19/4, 2021 at 6:23 Comment(0)
R
1

If anyone is wondering why they aren't getting email notifications for events - something I learned:

Email notifications are only sent for events in the FUTURE.

So if you're running tests with events in the past, know that notifications won't be sent.

(╯°□°)╯︵ ┻━┻

Roseola answered 2/5 at 16:24 Comment(0)
R
0

For this you should set the "remindOnRespondedEventsOnly" value to "true".

which means, Whether event reminders should be sent only for events with the user’s response status “Yes” and “Maybe”.

You can find this information here.

Hope that helps!

Rapacious answered 19/11, 2014 at 23:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.