Google Apps Script: How to force subscribe Google Group Members to a Google Calendar for G Suite

force change calendar subscriptions for Google Group members in Google Apps Script

Google Apps Script, G Suite Admins, Google Calendar, Calendar API,  AdminDirectory, GroupsAp

Note! This article is for G Suite users and admins. You won’t be able to apply the same code to Consumer accounts. 

Google Groups in  G Suite can be a really convenient and clean way to share users to drive folders and file locations, email users and set up Google+ community locations. However, I have come across some issues with sharing Google Calendar to Google Groups.

When you assign a Google Group email to a Google Calendar it sends out an email inviting the users in the group to accept the calendar into their list of shared calendars. The user must then accept the invitation before the calendar is added to their Google Calendar list of shared calendars…calendar.

The users receive an email message like this:

Hello Goat_GroupAlpha,

We are writing to let you know that has given you access to view events on the Google Calendar called “Test”.

Click this link to add the calendar.

– The Google Calendar Team

The Problem

In a large organisation, not all users in a group will add the calendar using the link. This might be okay but if the calendar is important or the user, as is often the case, simply just forgot to add it, then there will be emails to you the admin in the future asking you why they don’t have the calendar that everyone else has and has now missed some important event…sigh.

Another issue is that when a new user is added to a group when the group has already been added to a calendar, then that user will not receive an email invitation to the calendar and won’t be able to see the calendar.

Almost a Solution

When users are added individually to a calendar, the calendar is added automagically to their Google Calendar profile and placed in the Other calendars section of their calendar dashboard. An accompanying slightly different email is sent:


We are writing to let you know that has given you access to view events on the Google Calendar called “Test”.

We have automatically added this calendar to your Google Calendar account. You can hide or completely remove this calendar at any time.

– The Google Calendar Team

View Your Calendar.

This is optimal. It adds the calendar for the user and the user doesn’t have to do anything.

The problem is that we don’t want to waste time adding hundreds of users to multiple calendars by hand and have to manage them when we need to add new users or remove old users when they have left a group.

The Solution

To solve this problem we use Google Apps Script to get all the emails addresses of the members in a G Suite group, compare that against all the current members in the Calendar and add anyone who is missing.

We will use two Advance Google Services:

  1. Advanced Calendar Service
  2. Admin SDK Directory Service

In your Google Apps Script Editor, you will need to go to Resources > Advanced Google Services and activate these services.

If you are not an administrator for your organisation, that’s cool too. I’ll explain how you might be able to achieve the same thing by replacing the Admin SDK Directory Service with the GroupsApp service in the bonus material at the end.

The Code

The two main external variables for this program are the:

  • calendarId
  • groupEmail

I have stored them in the main run function addCalendarToGroupMembers() but you could equally make them global variables or draw this data from something like a Google Sheet, a form or a web-app.


As the name suggests, the calendar ID is the specific ID of the calendar. To find it, go to the calendar in your Google Calendar dashboard – in our case, this is the Test calendar – got down the left side-bar until you find one of your calendars you want to use. If you hover over it three ellipses will appear to the right of the calendar. Click on them and a window will appear. Click the option Settings and sharing.

Google Calendar Setting and Sharing option

On the left side-bar again under our Test calendar, there will be a list of options. We are going to click > Integrate calendar.  The first option here will be the Calendar Id.

Calendar Setting Integrate Calendar Calendar ID


Fortunately, the Group email is also the Id of your group. I’m pretty certain you can figure out how to get that one on your one.

Next, let’s dive into what the functions do:


As we mentioned above, this is the main run function for this code.

Once we added our external variables, our first task is to compare all the members of the calendar against all the members in our selected group.

We could simply re-add all the members of the group to the calendar, but we really don’t want to spam our users and we want to also improve our runtime.

Line 6, takes the groupEmail and calendarId variables and sends it to our getMissingEmailsFromGroup() function. It then returns a list of users in the group who have not been added to the calendar.

Line 9 then loops through all the users in the remaining userEmails.

Next, we get to work with the Advanced Calendar Service.

Let’s jump down to row 19 to see what we are using.

From the Calendar service, we are going to use the Access Control List (Acl) method. This method contains all the rules for managing the settings of the calendar. For our purpose, it also contains the names of all added members into the calendar and their associated permissions.

As you can see on line 19 we will be inserting new users into our Acl. Acl.insert take two parameters:

  1. The resources we want to add.
  2. The calendar ID.

Each Acl element contains a list of item objects. Each of these are basically the calendar rules for each member or resource. For us to add a new member to the calendar we need to add a new resource, provide it with a role, which in our case is, reader, then the scope for that resource. We want to make the user scope ‘user’ and the value of the scope will be the new member’s email.

You can see how we’ve added the new member details to lines 11-17.

We’ll encompass this in a try and catch statement just in case we get some bad emails or something.

Finally, we will use the Calendar.Calendars.get method to grab a summary (title) of the calendar. Then, we will log it out with a total count of users added to the calendar. You could change this around to an alert, toast on a Google Sheet or even an update back to a web app.

getMissingEmailsFromGroup(groupID, calendarID)

This function is called from the main addCalendarToGroupMembers() function. Its job is to compare the calendar member emails against the group emails and if there is a match, remove it from the group email list.

On lines 16 and 17 you can see that it calls two other functions to get the email lists from the calendar and group respectively.

Line 19 and 20 then begin the nested loops that go through each array of emails.

Line 22 then compares the two arrays and if there is a match, line 23 removes or splices out that email from the groupEmails array.

Finally, the function returns the remaining emails from the group to the main function addCalendarToGroupMembers().


In this function we use the Admin SDK Google Advanced Service to grab the member emails of a group. It then returns the list of emails back to getMissingEmailsFromGroup(groupID, calendarID) function.

To do this we use the Members method of the AdminDirectory retrieving a list of members and their details. This will retrieve data like this:

All we need out of this is the user’s email address.  To access this we first need to get to the members object array. From there we can use map to grab each email address. Briefly, map allow you to neatly take specific details of each item set in a loop and even modify it before returning the details as a new array.

Finally, we return our list of member’s emails.


This function is called from the getMissingEmailsFromGroup(groupID, calendarID) function. It uses the Calendar Advanced Services Acl again. It returns a list of member emails from the calendar.

Line 19 grabs the Access Control List…erh...list from the calendar. This is the list of all the rules and permissions added to the calendar.  It looks a little something like this:

As you can see all our member data is in the items array. So on line 22, we create the variable users to directly reference that array.

We can then remove one of the extraneous items that have a scope type of domain. We will do this by using filter on lines 26 and 27.

We don’t want all the other data for each member of the calendar. We only want the emails. To achieve this we then chained a map method to our filter that will iterate through each user item and only store the email (Lines 29-30).

All of the emails collected from the filter and map chain are stored in the emails variable on line 25. These are then returned back to the getMissingEmailsFromGroup(groupID, calendarID) function.

Bonus Code

While the above is really all you need to add new users to calendars, below are a few more tools for adding and removing users from calendars with Google Apps Script.

Remove All Users From a Calendar

This function removes all the users from a calendar who have the ‘reader’ role, which is essentially anyone who cannot make changes to the calendar.

Get Group Member Emails For Non-Admins

If you don’t have G Suite Admin privileges in your organisations. You might be able to use swap out the getUserEmailsInGroup(groupID) function with this one. The only provision here is that you must be a member of the group.

Force Calendar Subscriptions for Users not in a Group

This function simply forces calendar subscription for users who are not in a group. You can add multiple users and multiple calendars.

It is just like going into your calendar settings and manually adding users.


For me, I have found this pretty useful. It has significantly reduced complaints from users in groups who forgot to manually add a pertinent calendar ensuring they have the information that they need. It has also helped to ensure that new members of the group are added to the calendar and it will be ready for them to see.

To make things convenient, I added a bunch of buttons to a Google Sheet that lists all the groups from my domain and all the calendars I have edit access to. I can manually update a calendar with a group or set a twice-yearly time trigger to update group members on a calendar.

I hope you find the code useful for your own projects.

Looking to learn more about Google Apps Scripts in a more structured format? Udemy has some great courses that can get your from the basics to a real Google Apps Script pro!

Got a more specific problem you need help with, but don’t have the time to develop the skills? Fiverr’s your best bet to find a skilled Google Apps Script professional to solve your problem quickly and cheaply. *


*The above affiliate links have been carefully researched to get you to what you specifically need. If you decide to click on one of these links it will cost you just the same as going to the site. If you decide to sign up, I just get a little pocket money to help pay for the costs of running this website.

10 thoughts on “Google Apps Script: How to force subscribe Google Group Members to a Google Calendar for G Suite”

  1. Hi! thank you for that code…
    I tried to apply it, but I’m getting a slightly different result from what you wrote here
    my users gets the email with the link to click… and calendar not showing automagically on the web interface
    did anything change in google management? or am I missing something? any clue?

    1. Hi Daniele,

      I don’t think anything has changed. Are you using a GSuite (Google Workspace) or Google for Education account, or a normal consumer account?


    2. Hi Yashi, thank you for your reply
      G Suite for Education, admin account
      tried again, checked twice – and more and more 🙂
      same result: email invitation with link to click on, calendar not shown among Other calendars section of the users unless they click on the email link

      1. Hi Daniele,

        I’m not sure what is going on there. I ran a sample on a Google Workspace account and it seems okay. You wouldn’t think the G of Ed would be any different. Maybe sharing with student accounts might produce this over paid teacher/admin accounts but that doesn’t really make sense either.

        1. Hi Yashi, thank you for investigating.
          I also don’t think it’s a teacher/student sharing related problem: I tested it with admin-to-teacher invitation
          I never heard of such differences between Workspace and GSfEdu, too.
          If you’ve tested it again and it works, this make me think that the different behavior could be related to some kind of settings in my admin console. I’ll give a deeper look into the question. If any idea or solution, I’ll give you a feedback.
          Thank you again.

          1. Hey folks. I just stumbled upon this (THANK YOU) and noticed the line of code I needed to add was this between lines 32 and 33:

            That did the trick. The Calendar.Acl.insert adds the permissions. The Calendar.CalendarList adds it to the list.

            Thanks again! If anyone ever figures out how to add a non-Google calendar via scripting (like a feed how you would use BY URL), let me know!

  2. Hey there! Thanks for this excellent tutorial! Just wanted to give you a heads up that this may be outdated––when I individually invite users to a calendar (manually) they aren’t automatically added. The email they receive looks very similar to the one you posted above but instead says “After adding this calendar to your other calendars, you can hide or completely remove it whenever you want.” and includes a link to add the calendar. Am I sharing the calendar incorrectly? I’m doing it from the calendar’s settings page on

    Thanks again for the great information!

    1. Hi Josh,

      Thanks for the heads up. Are you working in a paid Google Workspace Domain account or a consumer account?


Leave a Reply