google-apps-scriptgoogle-groupsgoogle-groups-api

Changing Google Groups email from script throws Invalid Value


Being a super admin of my school's Google Workspace domain, I'd like to change Google Groups emails with a script. The following minimal script does his job changing the Name of the group:

function GroupUpd() {
  var OldEmail = '1z_22-23@abc.edu.it';
  var NewEmail = '2z_22-23@abc.edu.it';
  var NewName = "2Z";

  var group = AdminGroupsSettings.Groups.get(OldEmail);

  group.name=NewName;
  AdminGroupsSettings.Groups.patch(group, OldEmail);
}

Instead if I try to change the group email this code

function GroupUpd() {
  var OldEmail = '1z_22-23@abc.com';
  var NewEmail = '2z_22-23@abc.com';
  var NewName = "2Z";

  var group = AdminGroupsSettings.Groups.get(OldEmail);

  group.email=NewEmail;
  AdminGroupsSettings.Groups.patch(group, OldEmail);
}

gives:

GoogleJsonResponseException: API call to groupsSettings.groups.patch failed with error: Invalid Value

The very same happens if I use

AdminGroupsSettings.Groups.patch(group, OldEmail);

So, it seems to be a problem with NewEmail, but I have no idea what I am supposed to change.

DISCLAIMER: I'm a noob.


Solution

  • Instead Groups Settings API use the Directory API.

    References