Welcome to the Smartsheet Forum Archives


The posts in this forum are no longer monitored for accuracy and their content may no longer be current. If there's a discussion here that interests you and you'd like to find (or create) a more current version, please Visit the Current Forums.

Getting GroupMembers of Group using JavaSDK, Smartsheet API

Chris Be
Chris Be
edited 12/09/19 in Archived 2017 Posts

Hey Community!

 

I'm stuck at a certain point in my development process. I need to receive a list of all GroupMembers of a Group in Smartsheet. I tried the following:

 

//First, getting all groups of our smartsheet plan and storing the result in variable grouplist

//Iterate through all Groups...

 

for (Group g : grouplist) {

              

                // getMembers() returns a List of GroupMembers.
               // If the list is not null, print out all email-adresses of groupmembers
                if (g.getMembers() != null) {
                    for (GroupMember member : g.getMembers()) {
                        System.out.println(member.getEmail());
                    }
                } else {
                    System.out.println("No Group Members");
                }
            }

 

As an output I receive the following:

 

Admin-Team
No Members found
Alle
No Members found
BO-Supporter
No Members found
CT-Supporter
No Members found
EV-Supporter
No Members found
GT-Supporter
No Members found
HA-Supporter
No Members found
HO-Supporter
No Members found
HP-Supporter
No Members found

 

It seems like the function of Group object "getMembers()" always returns null in my case, says I'm always receiving an empty list of GroupMembers. This can't be because all groups got members for sure. Also if I print out other group details like owner, id, ... everything works fine, just the getMembers() function is not working for me, returns always null.

 

Am I doing something wrong? Is the function getMembers() not working correctly?

 

Thanks for your support

 

Cheers

Chris

 

Comments

  • Laurence White
    edited 02/28/17
  • Steve Weil
    Steve Weil Employee

    The listGroups() call returns 'lightweight' group objects that only contain a subset of properties. You'll need to call getGroup() to retrieve the full list of members.

     

    This is a common pattern in our API (and others) but can be confusing. It's required for performance and to reduce the amount of data retrieved and sent over the wire. If you look closely at the example response in the API docs you can see exactly what is returned.

     

    My code looks like this:

         PaginationParameters parameters = new PaginationParameters.PaginationParametersBuilder().setIncludeAll(true).build();
    PagedResult<Group> groups = ss.groupResources().listGroups(parameters);
    for (Group groupSummary : groups.getData()) {
    Group groupWithDetails = ss.groupResources().getGroup(groupSummary.getId());
    List<GroupMember> members = groupWithDetails.getMembers();
    for (GroupMember m : members) {
    String s = m.getEmail();
    }
    }
  • Hey Steve!

     

    Thanks a lot for your reply!

     

    Now I see what's going on here! Your code snippet works brilliant and all members are now displayed.

     

    Thank you very much for your support!

     

    Cheers

This discussion has been closed.