Groups are sets of users that can be used in collaborations.
- Get All Groups
- Create a Group
- Get Information About a Group
- Update a Group
- Delete a Group
- Get a Groups collaborations
- Create Membership
- Get Membership
- Update Membership
- Delete Membership
- Get Memberships for Group
- Get Memberships for User
Calling the static getAllGroups(BoxAPIConnection api)
will
return an iterable that will page through all of the user's groups.
Iterable<BoxGroup.Info> groups = BoxGroup.getAllGroups(api);
for (BoxGroup.Info groupInfo : groups) {
// Do something with the group.
}
The static createGroup(BoxAPIConnection api, String name)
method will
let you create a new group with a specified name.
BoxGroup.Info groupInfo = BoxGroup.createGroup(api, "My Group");
To look up the information about a group by the group's ID, instantiate the BoxGroup
object with the group ID and then call getInfo()
on the group. You can optionally call
getInfo(String... fields)
to specify the list of fields to retrieve for the group,
which can result in reduced payload size.
String groupID = "92875";
BoxGroup.Info groupInfo = new BoxGroup(api, groupID).getInfo();
To update a group, call updateInfo(BoxGroup.Info fieldsToUpdate)
method.
BoxGroup group = new BoxGroup(api, id);
BoxGroup.Info groupInfo = group.getInfo();
groupInfo.addPendingChange("name", "New name for My Group");
group.updateInfo(groupInfo);
A group can be deleted by calling the delete()
method.
BoxGroup group = new BoxGroup(api, "id");
group.delete();
A groups collaborations can be retrieved by calling the getCollaborations()
method.
BoxGroup group = new BoxGroup(api, "id");
group.getCollaborations();
Membership for the group can be created by calling the
addMembership(BoxUser user)
and
addMembership(BoxUser user, BoxGroupMembership.Role role)
methods.
BoxGroup group = new BoxGroup(api, "groupID");
BoxUser user = new BoxUser(api, "userID");
BoxGroupMembership.Info groupMembershipInfo = group.addMembership(user);
A groups membership can be retrieved by calling the BoxGroupMembership.getInfo()
method.
BoxGroupMembership membership = new BoxGroupMembership(api, id);
BoxGroupMembership.Info groupMembershipInfo = membership.getInfo();
A groups membership can be updated by calling the
BoxGroupMembership.updateInfo(BoxGroupMembership.Info fieldsToUpdate)
method.
BoxGroupMembership membership = new BoxGroupMembership(api, id);
BoxGroupMembership.Info info = membership.new Info();
info.addPendingChange("role", role);
membership.updateInfo(info);
A group can be deleted by calling the BoxGroupMembership.delete()
method.
BoxGroupMembership membership = new BoxGroupMembership(api, id);
membership.delete();
Calling the getAllMemberships(String... fields)
will return an iterable that will page through all of the group's memberships.
Optional parameters can be used to retrieve specific fields of the Group Membership object.
BoxGroup group = new BoxGroup(api, id);
Iterable<BoxGroupMembership.Info> memberships = group.getAllMemberships();
for (BoxGroupMembership.Info membershipInfo : memberships) {
// Do something with the membership.
}
Calling the BoxUser.getAllMemberships(String... fields)
will return an iterable that will page through all of the user's memberships.
Optional parameters can be used to retrieve specific fields of the Group Membership object.
BoxUser user = new BoxUser(api, id);
Iterable<BoxGroupMembership.Info> memberships = user.getAllMemberships();
for (BoxGroupMembership.Info membershipInfo : memberships) {
// Do something with the membership.
}