Announcement

Collapse
No announcement yet.

GET Users filter on role name

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • GET Users filter on role name

    Hi,

    I am using the user API with https://docs.espocrm.com/development/api-client-php/

    However I am not able to retrieve all users filtered on a certain role name.

    The user id: 65e98f9b2baf8b39e is linked to a role "Adviseur"

    "id": "65e98f9b2baf8b39e",
    "name": "adviseur_bouw",
    "userName": "adviseur_bouw",
    "type": "regular",
    "isActive": true,
    "rolesIds": [
    "660e7aa619df793c4",
    "660e7bc19d7f005ec"
    ],
    "rolesNames": {
    "660e7aa619df793c4": "Adviseur",
    "660e7bc19d7f005ec": "Werelds beheerder"
    },

    Now I like to filter on all users which are linked to the role "Adviseur"

    I tried a lot of things but this is the latest trial:

    ...
    $where = [
    [
    'type' => 'arrayAnyOf',
    'attribute' => 'rolesNames',
    'value' => ['Adviseur'],
    ],
    [
    'type' => 'equals',
    'attribute' => 'id',
    'value' => '65e98f9b2baf8b39e',
    ],
    ];

    $response = $client->request( Client::METHOD_GET, 'user', [
    'offset' => 0
    ,'select' => 'rolesNames'
    ,'maxSize' => 100
    ,'where' => $where
    ] );
    $parsedBody = $response->getParsedBody();
    var_dump($parsedBody);die();​

    ..

    But now response

    (note: If I remove the filter on roleNames I get the user​​)

    Does anyone have an idea how I can filter on rolename?

    Thanks

  • #2
    Maybe filter by the role ID instead.

    Add "Roles" filter to the User's Search layout. Search by the Role and see what API request is sent by the browser (F12 > Network tab).

    Comment


    • #3
      Hi Yuri,

      Thanks for this tip. Got me a step further. However I get a 403 error when I do exactly the same request through the the api (with my api user)


      Message Forbidden relation 'roles' in where.


      ... /api/v1/user?offset=0&maxSize=200&where%5B0%5D%5Btype%5D=l inkedWith&where%5B0%5D%5Battribute%5D=roles&where% 5B0%5D%5Bvalue%5D%5B0%5D=660e7aa619df793c4

      I have enabled all rights (in the role) for the api user, so how can I set the permissions for the api user to get the users filtered by role?

      Thanks

      By the way:
      I made an issue for the php client: https://github.com/espocrm/php-espo-api-client/issues/1
      However it looks like this git is not updated for 2 years now. Should I still use this php client?

      Comment

      Working...
      X