Google Group Member Deletion
Deletes members (email address) from Google Group. It is possible to respond to email newsletter delivery cancellation, or to delete automatically from the group when employees move or leave the company.
2017 © Questetra, Inc. (MIT License)
Configs
  • A: Set OAuth2 Config Name (at [OAuth 2.0 Setting]) *#{EL}
  • B: Select STRING/CHECKBOX for Group Address (Non-existent Error) *
  • C: Select STRING DATA for Email to Delete *
  • X: Select STRING DATA for Access Log (update)
Script
//// == 工程コンフィグの参照 / Config Retrieving ==
var oauth2  = configs.get( "conf_OAuth2" ) + "";
var dataIdB = configs.get( "conf_DataIdB" ); // (returns key)
var dataIdC = configs.get( "conf_DataIdC" ); // (returns key)
var dataIdX = configs.get( "conf_DataIdX" ); // (returns key)

//// == ワークフローデータの参照 / Data Retrieving ==
var targetGroups = [];
var dataDefB = engine.findDataDefinitionByNumber( dataIdB );
if( dataDefB.matchDataType("SELECT_CHECKBOX") ){
  var selectedGroups = data.get( dataIdB );
  for( var i = 0; i < selectedGroups.size(); i++ ){ // java.util.ArrayList
    var pushGroup = selectedGroups.get(i).getValue() + "";
    targetGroups.push( pushGroup );
  }
}else{
  var pushGroup = data.get( dataIdB ) + "";
  targetGroups.push( pushGroup );
}
var memberEmail = data.get( dataIdC ) + "";

//// == 演算 / Calculating ==
var accessLog = "";
var token = httpClient.getOAuth2Token( oauth2 );

for( var i = 0; i < targetGroups.length; i++  ){ // javascript array
  var uri = "https://www.googleapis.com/admin/directory/v1/groups/" + targetGroups[i] + "/members/" + memberEmail;
  var response = httpClient.begin()
    .bearer( token )
    .delete( uri );
  accessLog += "---DELETE request--- " + response.getStatusCode() + "\n";
  accessLog += response.getResponseAsString() + "\n";
}

//// == ワークフローデータへの代入 / Data Updating ==
if( dataIdX !== "" ){
  retVal.put( dataIdX, accessLog );
}

Download

  • GoogleGroup-memberDelete.xml
    • Since Rhino (deprecated) is specified as the script engine, a setting error will occur even if you install this in a workflow App
    • To use this Add-on, you need to change the script engine and modify the script accordingly
    • A modified version is in preparation

Capture

Notes

  • You need to Enable [Admin SDK Directory API] at Google Developers Console beforehand and obtain “Client ID” and “Client secret”
  • On G Suite domain administration screen, authorize “Client ID” and its communication scope

See also

%d bloggers like this: