Exact search option for user search | Community
Skip to main content

Exact search option for user search

  • October 24, 2024
  • 3 replies
  • 0 views

Hasan11

Hi, I'm using “/api/v2/users.json” endpoint to find users; however, it seems that it works as fuzzy search. 
For instance, with user phones “12345” and “1234” and query “123” I get both and occasionally results are not ordered from best match to least match. This may cause issue since user search should be conducted in exact match manner. Is there an option for it, or any alternative way to avoid handling this on code level?

3 replies

Greg29
  • October 24, 2024

Hi Hasan!

 

In the situation where you want an exact, it would probably be best to use the search API with the `type:user` parameter, which we outline in more detail here. Additionally, this documentation helps a bit more with explaining the use of the wild-card character in this query, which will be helpful. The API that it uses is different than the search API, but the wild-card aspect is still relevant. As an example:

 

{subdomain}.zendesk.com/api/v2/search?query=type:user%20phone:*2125551212

 

Let me know if you have any more questions!


Hasan11
  • Author
  • October 25, 2024

Thanks, Greg. I see your point, but using a wildcard or type filter doesn’t seem to solve my problem. Let me explain the scenario: in some cases, I update a user's identity by adding a prefix and then assign that original identity value to another user. I need to find the user with the exact phone number, but I haven't been able to do this with any API so far.
 

For example, with below data I want to give phone number 2125551212 for query and get user_2 (if possible only user_2 if not maybe at the beginning of the search result):

  • user_1 phone number: 2125551212_blocked
  • user_2 phone number: 2125551212
     

Greg29
  • October 28, 2024
Totally understand, that makes sense. Unfortunately, I don't believe that we're going to return anything like that as an exact search, since multiple users can have the same phone number and/or email address as parts of their identity. If you need that, you would have to build that filtering into your script to parse our results down to the phone numbers that met your criteria.