How to add member with name into group from Google Apps Script?

693 Views Asked by At

I want to add members to Google group using AdminDirectory.Members.insert.

This is my code:

function addGroupMember() {  
  var member = {
          name: {
              givenName: 'Jhon',
              familyName: 'Doe'
          },
          email: '[email protected]',
          role: 'MEMBER'
      };
  var newMember=AdminDirectory.Members.insert(member, '[email protected]');
}

The members is created into Group Members of Google Workspace, but without name, as you can see below:

enter image description here

There is one way to change Member by John Doe?

NOTE: The email domain is external, is not the same of the organization.

1

There are 1 best solutions below

4
On

You may want to take a deeper look at the documentation.

From the Member overview:

A Google Groups member can be a user or another group.

Also you can see that the Member resource has no attribute name so it's indeed impossible to assign it a name before creating the User resource.

What you can do right now is creating an User through the users.insert request. After that store the id of said user and insert it into a group with members.insert.


And of course if you have already created a bunch of users without specifying the names you can update them.