Google Apps Script: How to force subscribe Google Group Members to a Google Calendar for G Suite [Update 06 Apr 2022]

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 approach no longer force subscribes users to a Calendar. The new approach can be found here. [update 06 Apr 2022]

It appears that the approach below no longer force-subscribes users in a Group to a calendar. Google Made this change in March of 2020, some 7 months after the post was written.

Service accounts created on or after March 2, 2020 are only able to invite guests using domain-wide delegation of authority .

There is also a note in the Sharing Calendars chapter of the Calendar API information stating:

Note: Sharing a calendar with a user no longer automatically inserts the calendar into their CalendarList. If the user should be able to see and interact with the shared calendar, you will also need to call the CalendarList: insert() method.

While this explanation is no doubt helpful for general use, using the insert() method in CalendarList requires that the script be run by the user that needs to be shared.

One hint to a workaround can be found in the update notes referring to the ability to invite guests using domain-wide authority using a service account.

This is a pretty gnarly process to set up and write about and has taken some time to write about and test, but you can now find the tutorial here:

Having said all that, the script below does still contain some interesting use cases for using the Admin SDK service and Advanced Calendar API service in Google Apps Script, so I will leave it up until I can publish a solution.

The script below can now be modified to to extract the users in a group and then use a Service Account on each user to force subscribe them using the code in the tutorial link above.

Big thanks to Jeremy for bringing this to my attention and apologies, I could not find a quick fix.

~ Yagi 06 April 2022

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.

Hire me for our next Google Workspace project.

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.

?You can support me for free by using this Amazon affiliate link in your next tech purchase :Computers & Stuff! ?

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.

Create and Publish Google Workspace Add-ons with Apps Script Course 300px

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.

Create and Publish a Google Workspace Add-on with Apps Script Course

Need help with Google Workspace development?

My team of experts can help you with all of your needs, from custom app development to integrations and security. We have a proven track record of success in helping businesses of all sizes get the most out of Google Workspace.

Schedule a free consultation today to discuss your needs and get started or learn more about our services here.



24 Feb 2022 – Discovered from commenter Jeffery, that the force subscribe no longer works due to changes Google-side. Wrote an update note to head the tutorial. 

06 Mar 2022 – Wrote a tutorial on how to force subscribe a user to a Calendar in Google Apps Script using a Service Account and Domain Wide Delegation of Authority. Updated the header with links to this tutorial and suggestions on how to modifity the current tutorial. 

15 thoughts on “Google Apps Script: How to force subscribe Google Group Members to a Google Calendar for G Suite [Update 06 Apr 2022]”

  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. How would I reverse the script to remove the calendar permissions for users who are removed from the group?

  3. 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?


  4. Great work! I’m working with the coding framework you shared in “Force Calendar Subscriptions for Users not in a Group”. What if I simply want to set the visibility of a list of calendars to anyone in my domain. Essentially, ticking that box in the share settings that says “Make available for [your domain]”. I can get all of the Calendar Ids I want to work with into an array, but I’m stuck on how to proceed in changing their visibility. I thought maybe changing the scope type to domain would have solved that, but no dice. Do you have any code snippets that solve for that? It seems like it should be something simple, but I haven’t been able to figure it out yet. Thanks.

  5. Wow thanks for the prompt reply haha. I am definitely doing this from a paid Workspace account. I actually have a couple and I believe I tried this from a legacy business starter license and a different account with a legacy business standard license.

  6. Stumbled across this, love your work.
    How can I add multiple groups for this?

    1. Hi Jeremy,


      Your could change the groupEmail string to groupEmails array with your list of group emails.

      Add a new variable, call it say, allEmails.

      Next, loop through each group email in your array of groupEmails running getMissingEmailsFromGroup(the currently iterated group email, calendarId); pushing your emails to the allEmails group.

      Once done, replace userEmails on line 19 with your new allEmails loop and you should be good to go.

      Feel free to paste your code if you get stuck and I can guide you.


Leave a Reply