This script is designed to automate two main tasks using Google's Admin SDK and Apps Script: creating a new Google Group and adding a member to that group. It consists of a main function createGroupAndAddMember()
and a helper function getOAuthService()
. Here’s a breakdown of what each part does:
-
Initialization and Configuration:
groupEmail
,groupName
,description
: These variables are placeholders for the new group’s email, name, and description, respectively. You should replace them with actual values.memberEmail
: Email of the member to be added to the newly created group.
-
OAuth Service Setup (
getOAuthService()
):- Retrieves a stored service account key from the script's properties.
- Parses and uses this key to configure OAuth2 service with necessary details (client ID, private key, client email) and the required scopes which allow managing Google Groups and their members.
-
OAuth Access Check:
- Before proceeding, the script checks if the OAuth service has access. If not, it logs a URL for manual authorization.
-
Creating the Group:
- Constructs a payload with the group's details.
- Sends a POST request to the Google Admin SDK API to create a group using
UrlFetchApp.fetch()
. - Logs the success message with the created group's email.
-
Adding a Member to the Group:
- Constructs a payload with the member's email and role.
- Sends another POST request to add the specified email as a member to the newly created group.
- Logs the success message with the added member's email.