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

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
-
push!
-
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
Categories
- All Categories
- 14 Welcome to the Community
- Customer Resources
- 67.8K Get Help
- 474 Global Discussions
- 205 Use Cases
- 517 Announcements
- 5.5K Ideas & Feature Requests
- 87 Brandfolder
- 157 Just for fun
- 83 Community Job Board
- 521 Show & Tell
- 36 Member Spotlight
- 3 SmartStories
- 309 Events
- 37 Webinars
- 7.3K Forum Archives