Creating groups

A group entity represents an application group of users. You can create, retrieve, update, delete, and query group entities. See User entity properties for a list of the system-defined properties for group entities. In addition, you can create group properties specific to your application.

Request Syntax

Use the POST method to create a new group. Groups use paths to indicate their unique names. This allows you to create group hierarchies by using slashes. For this reason, you need to specify a path property for a new group.

Request URI

POST /{org_id}/{app_id}/groups

Parameters

Parameter

Description

uuid | org_id

Organization UUID or organization name

uuid | app_id

Application UUID or application name

request body

One or more sets of group properties, of which path is mandatory and must be unique. The path value may include forward slashes to denote hierarchical relationships.

Parameters

A path, optionally showing hierarchical relationships. This must be unique in your data store.

groupTitle

A friendly name for the group.

Example

In this example, the code to create a group is within code to find out if the group requested group path already exists for a group. This is like checking to see if a requested username exists before using that value for a new user. This example uses the Android SDK.

// A query statement with which to check for an existing group
// with the same path (which must be unique).
String queryText = "path='mynewgroup'";
// Call the DataClient method to find out if there's already
// a group with the path value the user entered. If not, add the
// group. Some callback methods are omitted for brevity.
dataClient.queryGroupsAsync(queryText, new QueryResultsCallback(){
// Called to receive the query response.
@Override
public void onResponse(Query query) {
ApiResponse response = query.getResponse();
List<entity> groups = response.getEntities();
if (groups.size() > 0){
// There's a group with this path, so display
// or log a message.
} else {
// Create a new group with data entered.
dataClient.createGroupAsync(groupPath,
groupTitle, new ApiResponseCallback(){
// Called to receive the response from the
// attempt to create a group.
@Override
public void onResponse(ApiResponse response) {
// Do something after successfully
// creating the group.
}
});
}
}
});

These are Usergrid.Client methods for adding groups to your data store. (Usergrid is the open source project on which these features are based.)