How to search all users using certain search criteria within user_metadata?

I would like to search all users which match certain search criteria within user_metadata. How should I go about doing this?

i.e. search all Auth0 users using UsersPage or equivalent function which allows us to filter users based on key/value pairs defined in user_metadata?

// sample scenarios
Scenario 1:

Auth0 organization feature is available and veeDNA authentication module will use it

The above implies there will be a separate organization for each tenant

auth0-org-a, user-a1 metadata will contain the mapping for tenant-id-a

auth0-org-a, user-a2 metadata will contain the mapping for tenant-id-a

auth0-org-b, user-b1 metadata will contain the mapping for tenant-id-b

auth0-org-b, user-b2 metadata will contain the mapping for tenant-id-b

i.e. each Auth0 organization will contain its own users

Scenario 2:

Auth0 organization feature is available and veeDNA authentication module will use it

We will use a single organization for all tenants

auth0-org , user-a1 metadata will contain the mapping for tenant-id-a

auth0-org , user-a2 metadata will contain the mapping for tenant-id-a

auth0-org , user-b1 metadata will contain the mapping for tenant-id-b

auth0-org , user-b2 metadata will contain the mapping for tenant-id-b

i.e. the only default Auth0 organization will contain all users

Hi @selvi,

Thanks for reaching out to the Auth0 Community!

I understand that you would like to search all users and filter them by user_metadata.

To do so, you can use the Management API List or Search Users endpoint to query for the user’s user_metadata.

In the q parameter of the request, filter for the user_metadata using the following syntax:

_exists_:user_metadata.YOUR_KEY

For example, if the user’s user_metadata looks like the following:

//user_metadata
{
   "fav_color": "green",
   "authorization": {
     "admin": true
   }
}

You could query for the fav_color by making this request:

_exists_:user_metadata.fav_color

This request returns the value "green". You could also query for the values within a nested object:

_exists_:user_metadata.authorization.admin

This request returns the value true.

With that, you can search all users and filter them by user_metadata.

Next, from your proposed scenarios, I suggest using a single Organization (Scenario 2) if all the “tenants” belong to the same Organization. Otherwise, you will have to isolate them in different Organizations.

Lastly, note that the user_metadata is stored in the user’s profile and not in the Organization. Therefore, how you configure the Organization feature should be separate from searching all users and filtering them by user_metadata.

Hoped this helps!

Please let me know if you have any additional questions.

Thank you.

1 Like

Thanks for the information. Helpful!

1 Like