searchProfiles

var filters = {
   // filter can contains an array `roles` with a list of role identifiers
  roles:  ['myrole', 'admin'],
  // filter can handle pagination with properties `from` and `size`
  from: 0,
  size: 10
};

// Using callbacks (NodeJS or Web Browser)
kuzzle
  .security
  .searchProfiles(filters, function(error, result) {
    // result is a JSON Object with the following properties:
    // {
    //   total: <number of found profiles>,
    //   documents: [<Profile object>, <Profile object>, ...]
    // }
  });

// Using promises (NodeJS)
kuzzle
  .security
  .searchProfilesPromise(filters)
  .then(result => {
    // result is a JSON Object with the following properties:
    // {
    //   total: <number of found profiles>,
    //   documents: [<Profile object>, <Profile object>, ...]
    // }
  });
JSONObject filters = new JSONObject()
  // filter can contains a "roles" array with a list of role IDs
  .put("roles", new JSONArray().put("myrole", "admin"))
  // search results can be paginated
  .put("from", 0)
  .put("size", 10);

kuzzle
  .security
  .searchProfiles(filters, new ResponseListener<SecurityDocumentList>() {
    @Override
    public void onSuccess(SecurityDocumentList profiles) {
      // Contains a profiles list
      for(Profile profile : profiles.getDocuments()) {

      }

      // And the total number of profiles, regardless of pagination
      profiles.getTotal();
    }

    @Override
    public void onError(JSONObject error) {

    }
  });
<?php

use \Kuzzle\Kuzzle;
use \Kuzzle\Security\Profile;
use \Kuzzle\Util\ProfilesSearchResult;

$filters = [
  'roles' => [
      'admin',
      'myrole'
  ]
];

$options = [
  'from' => 0,
  'size' => 1
];

$kuzzle = new Kuzzle('localhost');
$security = $kuzzle->security();

try {
  $result = $security->searchProfiles($filters, $options);

  // $result instanceof ProfilesSearchResult
  foreach($result->getProfiles() as $profile) {
    // $profile instanceof Profile
  }
}
catch (ErrorException $e) {

}

Callback response:

{
  "total": 124,
  "documents": [
    // array of Profile objects
  ]
}

Executes a search on profiles according to a filter


searchProfiles(filters, [options], callback)

ArgumentsTypeDescription
filtersJSON ObjectList of filters to retrieves roles
optionsJSON ObjectOptional parameters
callbackfunctionCallback handling the response

Available options:

OptionTypeDescriptionDefault
fromnumberStarting offset0
queuablebooleanMark this request as (not) queuabletrue
sizeintegerNumber of hits to return20

Options

FilterTypeDescriptionDefault
rolesarrayContains an array roles with a list of role idundefined

Callback response

Resolves to a JSON Object containing the number of found profiles and an array of Profile objects.