Adding a user to a group

API BaaS will reach end-of-life (EOL) on June 30, 2019.
Users of the push notifications feature should plan to migrate off API BaaS for that functionality
before April 11, 2019. For more information, see Apigee
deprecations, retirements, and CPS changes.

You can add users to groups from client code using cURL commands or one of the SDKs, as
described here.

When setting up your application on the server, you might find it easier and more convenient
to create and populate groups with the admin portal. There, you can create groups, create roles,
and define permission rules that govern user access to data and services in your application. For
more information, see Security & token
authentication.

cURL

Use the POST method to add
a user to a group. If the named group does not yet exist, an error message is returned.

Example

NSString *groupId = @"mygroup";
NSString *userName = "joe";
// Add the user through a call to an SDK method.
[[self.apigeeClient dataClient] addUserToGroup:userName group:self.groupId
completionHandler:^(ApigeeClientResponse *response)
{
if ([response completedSuccessfully]) {
// This might be a good place to show the
// updated list of users in the group.
} else {
// You might log or display a message here.
}
}];

Parameters

Example

// Current user set from an input on the home page.
var userName = "joe";
// Group selected from the dropdown.
var selectedGroupPath = "mygroup"
// Prepare an Apigee.Group entity for the
// group to which you'll add the user.
var groupOptions = {
client:apigeeClient,
path:selectedGroupPath
}
var group = new Apigee.Group(groupOptions);
// Get the group data.
group.fetch();
// Options to define the user you'll be adding to
// the group.
var options = {
'username':currentUser,
'type':'users'
}
// Call an SDK method to get an entity representing
// the user so it can be used when adding the
// user to the group.
apigeeClient.getEntity(options, function(error, entity, data){
if (error) {
// Display or log a message.
} else {
// Options that specify the user entity.
// The method for adding a user to a group requires
// an entity, rather than just user properties.
var addUserOptions = {
user : entity
}
// Call an SDK method to add the user.
group.add(addUserOptions, function(error, data, entities){
if (error){
// Display or log a message.
} else {
// Having succeeded, you might refresh a list
// the group's users.
}
});
}
});