1

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.

1 Answer 1

1

There has been a recent change in the way Google treats calendars created / modified by a service account.

It is no longer possible to add users to such a calendar without the users' manual approval.

The only way to get around it (works only for domain users) is to Perform G Suite Domain-Wide Delegation of Authority. Basically, make the service account work on the user's behalf and make the service account accept the invitation on the users behalf.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.