Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending email notifications for Events via Google Calendar API

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)?

like image 996
spiritusozeans Avatar asked Nov 19 '14 03:11

spiritusozeans


People also ask

Can you link an email to a Google Calendar event?

Create an event from a Gmail messageYou can create a calendar event from a Gmail message. The calendar event automatically invites people on the Gmail message, and includes the Gmail message in the calendar event description. On your computer, go to Gmail.

Does Google Calendar send notifications for tasks?

To receive notifications on your mobile, make sure they are enabled for the Google Tasks app on your Android phone or iPhone. You can check if notifications are enabled in your phone's settings.


1 Answers

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 () {});
like image 54
linaa Avatar answered Sep 30 '22 10:09

linaa