Google Calendar API v3 service account not sending notification when creating an event

Viewed 926

I'm trying to use a google service account to create a calendar event (in its own calendar) and invite some attendees.

When I create the event using a service account and JWT authentication, the event is created successfully but the invitees do not receive email notifications - see below code. The email notification is sent if I use a client account but I would rather not resort to this.

Am I doing something wrong?

var google = require('googleapis');
var SCOPES = ['https://www.googleapis.com/auth/calendar'];

var key = require("./API-Project-key.json");
var jwtClient = new google.auth.JWT(key.client_email, null, key.private_key, SCOPES, null);

jwtClient.authorize(function(err) {
    if (err) {
        console.log(err);
        return;
    }
    createEvent(jwtClient);

});

/**
 * @param {google.auth.OAuth2} auth An authorized OAuth2 client.
 */
function createEvent (auth) {
    var calendar = google.calendar('v3');


    var event = {
        'summary': 'Test Event',
        'location': 'London, UK',
        'description': 'This is a sample event',
        'start': {
            'dateTime': '2016-03-15T20:00:00',
            'timeZone': 'Europe/London',
        },
        'end': {
            'dateTime': '2016-03-15T21:00:00',
            'timeZone': 'Europe/London',
        },
        'attendees': [
            {'email': 'myemail@mydomain.com'}
        ]
    };

    calendar.events.insert({
        auth: auth,
        calendarId: 'primary',
        sendNotifications: true,
        resource: event
    }, function (err, event) {
        if (err) {
            return console.log(err, event);
        }
        return console.log(event);
    });
}
1 Answers

"sendNotifications" is now depreciated. You need to change it to "sendUpdates" and pass in the parameter "all" as shown here:

calendar.events.insert({
    auth: auth,
    calendarId: 'primary',
    sendUpdates:'all',
    resource: event
}, function (err, event) {
    if (err) {
        return console.log(err, event);
    }
    return console.log(event);
});

From the Google documentation:

Acceptable values are:

"all": Notifications are sent to all guests.
"externalOnly": Notifications are sent to non-Google Calendar guests only.
"none": No notifications are sent. This value should only be used for migration use cases (note that in most migration cases the import method should be used).
Related