Creating users

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

Although the password parameter is not mandatory, if you don't specify it, the user will not be able to log in using username and password credentials. If a password is not specified for the user, and you're an Admin, you can set a password for the user (see Setting a password).

Note: The username can contain any combination of characters, including those that represent letters, numbers, and symbols.

Example

// Password, email and name are optional for the user entity, but required for the signup method.
// If you don't want them set in your user entity, set their values to null.
// Variable to collect data to send with the request.
var userName = "johndoe"; // Must be unique.
var name = "John Doe";
var email = "john.doe@example.com";
var password = "johnsdogsname";
// Options representing the new user to add.
var options = {
'username':userName,
'type':'users'
}
// Call an SDK method to get an entity representing
// the user. If no user is returned, then add one.
apigeeClient.getEntity(options, function(error, entity, data){
if (error) {
// If there's an error, it could be because the username
// wasn't found. In that case, it's safe to add
// a user with that name.
var errorMessage = error.name;
if (errorMessage == "service_resource_not_found"){
// Call an SDK method to create a new user with
// data collected from the form.
apigeeClient.signup(userName, password, email,
name, function (error, entity, data) {
if (error) {
// Log or display a message.
} else {
// Refresh the user list to include the new user.
getUsers();
}
});
}
} else {
// Display a message because there's already a user with that username.
}
});