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.

createRole #

Create a new role in Kuzzle.

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

createRole(id, content, [options], callback) #

ArgumentsTypeDescription
idstringUnique role identifier
contentJSON ObjectA plain JSON object representing the role
optionsstring(Optional) Optional arguments
callbackfunctionCallback handling the response

Options #

FilterTypeDescriptionDefault
replaceIfExistbooleanIf the same role already exists: throw an error if sets to false. Replace the existing role otherwisefalse
queuablebooleanMake this request queuable or nottrue
refreshstringIf set to wait_for, Kuzzle will wait the persistence layer to finish indexing (available with Elasticsearch 5.x and above)undefined

Callback Response #

Returns a Role object.

Usage #

var roleDefinition = {
  controllers: {
    "*": {
      actions: {
        "*": true
      }
    }
  }
};
// You can chose to replace the given role if already exists
var options = {
  replaceIfExist: true
};
// Using callbacks (NodeJS or Web Browser)
kuzzle
  .security
  .createRole('myrole', roleDefinition, options, function(error, response) {
    // result is a Role object
  });
// Using promises (NodeJS)
kuzzle
  .security
  .createRolePromise('myrole', roleDefinition, options)
  .then((response) => {
    // result is a Role object
  });