App Script for Modifying Google Groups

Posted on Tue 23 February 2016 in google-apps

Google App Script is a little-known, yet powerful development platform for enhancing and automating google services. I use it for administration and building custom tools. Here are some things I've used it for

  • a web app that scans emails for certain patterns and puts the results in email
  • index email into a sql db to build charts & reports (e.g. 7d volume, top senders)
  • automate account settings changes & cleanup
  • bulk migration of email between accounts or from shared accounts to groups
  • various google spreadsheet formulas
  • various google docs macros like timestamps

Sadly, the platform is a bit tricky to set up--but only needs setting up once. Let's intro the setup and a basic configuration

Setting Up the App Script

Step 1: Creating the Script

Visit Google App Script Start and hit "start scripting". If you're an apps admin, make sure you use your admin account for this and all tasks

Step 2: Create a test Project in the Google Console

Visit the Google Developers Console and create a new project. Copy the project ID to use in your app script

Step 3: Activate APIs in your Project

This is why we use a single project for multiple scripts. Here you can activate APIs and the settings will be re-used across all scripts that use the project.

In the console, go to your project, then "APIs". Activate the "Admin Directory SDK" and "Groups Settings API".

Step 4: Bind your project to your app script

In your app script, click "Resources -> Developers Console Project" and enter your new project ID. It will ask for a confirmation to delete the temporary project connected previously to your app-script.

Step 5: Activate Advanced Services In Your App Script

In your app script, click "Resources -> Advanced Services", then Activate AdminDirectory and GroupsSettingsAPI

Building the Script

Now we're actually ready to code.

This simple method will fetch all of your groups, and then set the showInGroupDirectory bit on. This way your team will be able to see a complete list of all of your groups here:

function setGroupsDirectory() {
  // my_customer is a keyword for your own account.  domain should be your domain
  var groups =   AdminDirectory.Groups.list({customer: "my_customer", domain: ""});
  for(var i = 0; i < groups.groups.length; i++){
    var response = AdminGroupsSettings.Groups.update({showInGroupDirectory: "true"}, groups.groups[i].email);

In my case this saved me about 2 hours worth of clicking through our ~60 groups through the management UI and activating the directory.