Skip to content

Latest commit

 

History

History
218 lines (160 loc) · 7.82 KB

groups.md

File metadata and controls

218 lines (160 loc) · 7.82 KB

Groups

Groups are sets of users that can be used in collaborations.

Get All Groups

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.
}

Create a 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");

Get Information About a 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();

Update a Group

To update a group, call updateInfo(BoxGroup.Info fieldsToUpdate) method.

BoxGroup group = new BoxGroup(api, id);
BoxGroup.Info groupInfo = group.getInfo();
groupInfo.setName("New name for My Group");
group.updateInfo(groupInfo);

Delete a Group

A group can be deleted by calling the delete() method.

BoxGroup group = new BoxGroup(api, "id");
group.delete();

Get first page of a Group's Collaborations

The first page of a group's collaborations can be retrieved by calling the getCollaborations() method.

BoxGroup group = new BoxGroup(api, "id");
Collection<BoxCollaboration.Info> collaborations = group.getCollaborations();

Get all of a Group's Collaborations

All of a group's collaborations can be retrieved by calling the getAllCollaborations(String... fields) method. An iterable is returned to allow a user to iterate until the last collaboration.

BoxGroup group = new BoxGroup(api, "id");
Iterable<BoxCollaboration.Info> collaborations = group.getAllCollaborations();

Create Membership

Membership for the group can be created by calling the addMembership(BoxUser user) and addMembership(BoxUser user, BoxGroupMembership.GroupRole role) methods.

BoxGroup group = new BoxGroup(api, "groupID");
BoxUser user = new BoxUser(api, "userID");
BoxGroupMembership.Info groupMembershipInfo = group.addMembership(user);

Get Membership

A groups membership can be retrieved by calling the BoxGroupMembership.getInfo() method.

BoxGroupMembership membership = new BoxGroupMembership(api, id);
BoxGroupMembership.Info groupMembershipInfo = membership.getInfo();

Update Membership

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.setGroupRole(BoxGroupMembership.GroupRole.MEMBER);
membership.updateInfo(info);

Delete Membership

A group can be deleted by calling the BoxGroupMembership.delete() method.

BoxGroupMembership membership = new BoxGroupMembership(api, id);
membership.delete();

Get Memberships for Group

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.
}

Get Memberships for User

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.
}