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