UsersResource.search(search, start, max) doesn't work

Hi,
Can someone help me with this issue?
According to documentation (UsersResource (Keycloak Docs Distribution 11.0.3 API))

Search for users whose username or email matches the value provided by search. The search argument also allows finding users by specific attributes as follows:
id: - Find users by identifier. For instance, id:aa497859-bbf5-44ac-bf1a-74dbffcaf197

This should allow us to get the user by email, but this doesn’t work.
search - the value to search. It can be the username, email, or any of the supported options to query based on user attributes

I tried to call this method usersResource.search(“email:user@email.com”, 0,100); but in the case when any other attribute than id is used it doesn’t retrieve anything, the only id works.

Am I missing something?

The admin console uses this API as well so you can check your queries there. I don’t think you need to prefix the search query with “email:” it will use the value as is for all fields

1 Like

This is not admin api. Admin API uses similar methods. This method is invoked from Java back end when keycloak-admin-client dependency is used.
I didn’t find any dependency for invoking admin resources on the same way like when client dependency is used…

The keycloak-admin-client just uses the same underlying API as the admin console - the Admin API. So, it’s all the same…

The main question is:
In the documentation, why do you have something that doesn’t work, like passing the attribute (e.g. email:xxxx@xxx.com) ?
Second, keycloak-admin-client sends the request to [keycloak]/auth/realms/[realm]/…
while admin is [keycloak]/auth/admin/realms/[realm]/…
how is this the same (maybe, I didn’t write a fully correct URL but it’s similar)?
If keycloak-admin-client uses the same API as the admin console, how can I use those admin resources that the console uses?

@npasic could you point to the documentation where it states that? I’m not sure what you mean with the difference between urls admin client and admin console use the same endpoint. The admin client is just a small library that simply invokes the rest endpoints that the admin console uses as well so you can see what it passes to the search endpoint to see how you can use it. Also there are tests for each function of the admin client so there you can also find examples:

const users = await adminClient.users.find({ first: 0, max: 100, search: "user@email.com" });

What ever you put into the search parameter will be matched against username email. to query a user with some attributes you can use:

// if you omit first and max default of 0 and 20 will be used
const users = await adminClient.users.find({key: 'value'});