0

  var form = FormApp.openById('1IErsge8yafg0UOltvhecAMhRd5Yh1VXJdhkI');
  var groupID = "mygroup@googlegroups.com";

  var formResponses = form.getResponses();
  for (var i = 0; i < formResponses.length; i++) {
    var formResponse = formResponses[i];
    var itemResponses = formResponse.getItemResponses();
    var email = itemResponses[1].getResponse();
    Logger.log(email);
    var newMember = {email: email, role: "MEMBER"};
    AdminDirectory.Members.insert(newMember, groupID);
  }

}

This is the code I've written and I'm getting an error enter image description here

After some research I found out that the error is because I don't have a G Suite subscription.

However, I am not able to find anything about how achieve the same task without a G Suite subscription. Can anyone please help me with that?

Thanks in advance!

Rubén
  • 34,714
  • 9
  • 70
  • 166
abhi
  • 25
  • 6
  • You need the id. You can make a test request [here](https://developers.google.com/admin-sdk/directory/reference/rest/v1/groups/list) and see the id. It looks like this: `22y111xx3f8ri5j` That worked for me, just tested it. – RemcoE33 Apr 10 '22 at 19:00
  • Please add more details. Are you a Google Workspace Admin? Are you able to list the groups in your domain? P.S. Error messages should be added as text, not as images. P.S.S. Related https://stackoverflow.com/q/21253849/1595451 – Rubén Apr 10 '22 at 19:28
  • In addition, you have an example in the official documentation: [Add group member](https://developers.google.com/apps-script/advanced/admin-sdk-directory#add_group_member) – Emel Apr 11 '22 at 12:00
  • @Rubén I am not a Google workspace admin. I'm quite new to stack overflow and I didn't know we were supposed to add error as text. Thanks for the information! – abhi Apr 12 '22 at 15:25
  • Thanks for your reply abhi. Please consider to [edit] the question to replace the error image by the error text. – Rubén Apr 12 '22 at 15:31

1 Answers1

2

As you aren't Google Workspace Admin, please checkout the Jay Lee's answer to Google Groups API add Member. Tl;Dr: AdminDirectory can be used only by Google Workspace Admins.

You might try to use the Groups Service to get information about a Google Group but it hasn't a method to add users to a group, so your only options are to add the users manually or to use web-browser automation tool.

Resources

Related

Rubén
  • 34,714
  • 9
  • 70
  • 166