Google Groups: Members, Delete
Google Groups: Members, Delete
Removes an email address from the specified group which is created in Google Groups. Removing the email address from multiple groups at once is also possible. You can automate the operations for a personnel change.
Configs
  • A: Select HTTP_Authz Setting *
  • B: Set Email Address to Delete *#{EL}
  • B2: Set Boolean for log of email (true: DEFAULT, false: none)#{EL}
  • C: Set Emails of Groups from which the Email will be deleted *#{EL}
Script (click to open)
// GraalJS Script (engine type: 2)
/*
NOTES
- Google Group for Google Workspace can be used as a team mailing list.
- This addon will automatically delete one email to groups via Google APIs. (Admin SDK Directory API)
- You can delete group email addresses as well as user email addresses.
- If the email does not already exists, the Warning log (409) will be output.
- If the log output of the target email address is not appropriate, set "false".
    - Personal information protection, various laws and regulations, security policies, etc.

NOTES-ja
- ビジネス向けGoogleグループは、メーリングリストとして利用ができます。(Google Workspace)
- このアドオンは、1つのメールアドレスを Google API 経由で自動削除します。(Admin SDK Directory API)
- ユーザアドレスだけでなく、グループアドレスも削除できます。
- 当該メールアドレスが、既に存在しない場合は、Warning ログ(404)が出力されます。
- 対象メールアドレスのログが適切でない場合、ログ出力に "false" を設定して下さい。
    - 個人情報保護の観点や各種法令セキュリティポリシーなど
*/


/*
APPENDIX
- OAuth Setting sample [HTTP Authorization Setting]
    - "Authorization Endpoint URL"
        - https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force
    - "Token Endpoint URL"
        - https://accounts.google.com/o/oauth2/token
    - to get your "ClientId" and "Secret"
        - Access to https://console.developers.google.com/apis/credentials
- Authorization Scopes (one of the following)
    - https://apps-apis.google.com/a/feeds/groups/
    - https://www.googleapis.com/auth/admin.directory.group
    - https://www.googleapis.com/auth/admin.directory.group.member

APPENDIX-ja
- OAuth 設定例([HTTP認証設定]の例)
    - "Authorization Endpoint URL"
        - https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force
    - "Token Endpoint URL"
        - https://accounts.google.com/o/oauth2/token
    - なお "ClientId" と "Secret" は開発者コンソールにアクセスして取得します。
        - Access to https://console.developers.google.com/apis/credentials
- 認可スコープ(以下のいずれか)
    - https://apps-apis.google.com/a/feeds/groups/
    - https://www.googleapis.com/auth/admin.directory.group
    - https://www.googleapis.com/auth/admin.directory.group.member
*/


//////// START "main()" /////////////////////////////////////////////////////////////////
main();
function main(){ 

//// == Config Retrieving / 工程コンフィグの参照 ==
const strAuthzSetting   = configs.get( "AuthzConfA" ); // required (Authz by Basic_AuthN)
  engine.log( " AutomatedTask Config: Authz Setting: " + strAuthzSetting );
const strLog            = configs.get( "StrConfB2" ) + "";
  let boolLog           = true;
  if( strLog          === "false" ){
      boolLog           = false;
  }
const strTargetEmail    = configs.get( "StrConfB" ) + "";
  if( boolLog ){
    engine.log( " AutomatedTask Config: Target Email: " + strTargetEmail );
  }
const strGroupEmails    = configs.get( "StrConfC" ) + ""; // "groupKey"
  if( strGroupEmails   === "" ){
    throw new Error( "\n AutomatedTask ConfigError:" +
                     " Config {C Group Address} not specified \n" );
  }
  const arrGroupEmails  = strGroupEmails.split("\n");
  engine.log( " AutomatedTask Config: Group Emails: " + arrGroupEmails.length );
  engine.log( strGroupEmails );


//// == Data Retrieving / ワークフローデータの参照 ==
// (nothing)


//// == Calculating / 演算 ==

/// Removes a member from a group.
/// (Google Workspace Developer > Admin SDK > Directory API)
/// https://developers.google.com/admin-sdk/directory/reference/rest/v1/members/delete

for( let i = 0; i < arrGroupEmails.length; i++ ){
  // request1, prepare
  let deleteUri1  = "https://admin.googleapis.com/admin/directory/v1/groups/" +
                 arrGroupEmails[i] + "/members/" + strTargetEmail;
  let request1 = httpClient.begin(); // HttpRequestWrapper
      request1 = request1.authSetting( strAuthzSetting ); // with "Authorization: Bearer XX"
  // request1, try
  const response1     = request1.delete( deleteUri1 ); // HttpResponseWrapper
  if( boolLog ){
    engine.log( " AutomatedTask ApiRequest1 Start: " + deleteUri1 );
  }else{
    engine.log( " AutomatedTask ApiRequest1 Start: " + arrGroupEmails[i] );
  }
  const response1Code = response1.getStatusCode() + ""; // (primitive string)
  const response1Body = response1.getResponseAsString() + "";
  engine.log( " AutomatedTask ApiResponse Status: " + response1Code );
  if( response1Code === "404"){
    engine.log( " AutomatedTask ConflictWarning:" +
                      response1Code + "\n" + response1Body );
  }else if( response1Code !== "204"){
    throw new Error( "\n AutomatedTask UnexpectedResponseError: " +
                      response1Code + "\n" + response1Body + "\n" );
  }
  // response1, parse
  /* engine.log( response1Body ); // debug
  (response none)
  */
}


//// == Data Updating / ワークフローデータへの代入 ==
// (No Output except Console Log)


} //////// END "main()" /////////////////////////////////////////////////////////////////



Download

2021-01-23 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/google-groups-members-delete/
The Addon-import feature is available with Professional or Enterprise edition.

Notes

  • Google Group for Google Workspace can be used as a team mailing list.
  • This addon will automatically delete one email to groups via Google APIs. (Admin SDK Directory API)
  • You can delete group email addresses as well as user email addresses.
  • If the email does not already exists, the Warning log (409) will be output.
  • If the log output of the target email address is not appropriate, set “false”.
    • Personal information protection, various laws and regulations, security policies, etc.

Capture

Removes a user from the specified Google Groups. It is also possible to remove from multiple groups at once. You can automate operations during personnel shift.

Appendix

See also

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: