SDK
SDK Javascript v5.x
1

You are currently looking at the documentation of a previous version of Kuzzle. We strongly recommend that you use the latest version. You can also use the version selector in the top menu.

createUser #

Create a new user in Kuzzle.

There is a small delay between user creation and its availability in our search layer (usually a couple of seconds). That means that a user that was just created may not be returned by the searchUsers function at first.

createUser(id, user, [options], [callback]) #

ArgumentsTypeDescription
idstringUnique user identifier
userJSON ObjectA plain JSON object representing the user (see below)
optionsstring(Optional) Optional arguments
callbackfunctionCallback handling the response
refreshstringIf set to wait_for, Kuzzle will wait the persistence layer to finish indexing (available with Elasticsearch 5.x and above)

The user object to provide must have the following properties:

  • content (JSON object): user global properties
    • This object must contain a profileIds properties, an array of strings listing the security profiles to be attached to the new user
    • Any other property will be copied as additional global user information
  • credentials (JSON object): a description of how the new user can identify themselves on Kuzzle
    • Any number of credentials can be added, each one being an object with name equal to the authentication strategy used to authenticate the user, and with the login data as content.
    • If this object is left empty, the user will be created in Kuzzle but the will not be able to login.

Options #

FilterTypeDescriptionDefault
queuablebooleanMake this request queuable or nottrue

Callback Response #

Returns a User object.

Usage #

var user = {
  content: {
    // A "profileIds" field is required to bind a user to existing profiles
    profileIds: ['admin'],
    // Additional information may be provided
    firstname: 'John',
    lastname: 'Doe'
  },
  credentials: {
    // Authentication strategy to use
    "local": {
      // The necessary information to provide vary,
      // depending on the chosen authentication strategy
      "username": "jdoe",
      "password": "secret password"
    }
  }
};
var options = {};
// Using callbacks (NodeJS or Web Browser)
kuzzle
  .security
  .createUser('myuser', user, options, function(error, response) {
    // result is a User object
  });
// Using promises (NodeJS)
kuzzle
  .security
  .createUserPromise('myuser', user, options)
  .then(response => {
    // result is a User object
  });