I am using a service account to create new calendars in our system.
async function newCalendar (email) {
console.log('creating calendar for username', email, 'as', config.google.calendar.clientEmail);
const auth = await getAuth();
const calendar = google.calendar({version: 'v3', auth});
const newCal = await calendar.calendars.insert({
resource: {summary: `SYSCALENDAR(${email})`}});
const calendarId = newCal.data.id;
const associated = await calendar.acl.insert({
calendarId,
requestBody: {
role: 'reader',
scope: {
type: 'user',
value: email
}
},
sendNotifications: false
});
return calendarId;
}
As shown above, the calendars are created as owned by the service account that performs the calendars.insert call.
I am also injecting a calendar.acl record, which I believe grants permission for the user identified by 'email' to access this calendar.
In this snippet, I have:
sendNotifications: false
If I set this to true, the user receives an email about the new ACL entry, and can click to add the calendar to their own calendarList.
I don't want the user to have to do this, and instead would like to add the calendar to the calendarList in code, as the service account.
This is not as simple as calendarList.insert(calendarId) as that will insert the calendar into the service accounts calendarList.