Email Validation for Retrieve Users with Get Users by Email Endpoint

I am trying to use “Retrieve Users with Get Users by Email Endpoint” (/api/v2/users-by-email) but I am getting error as

400 Bad Request: [{“statusCode”:400,“error”:“Bad Request”,“message”:“Query validation error: ‘Object didn’t pass validation for format email: testUser1%2Bsan1%40gmail.com’ on property email (Email address to search for (case-sensitive)).”,“errorCode”:“invalid_query_string”}]

URL:- https://DOMIAN/api/v2/users-by-email?email=testUser1%2Bsan1%40gmail.com
Email:- testUser1+san1@gmail.com

I am using Spring boot app to make API calls and here is the code
restTemplate.exchange(uri.toString(), HttpMethod.GET, entity, String.class);

I tried encode email address like URLEncoder.encode(email, Charset.defaultCharset()).

Did I missed anything while encoding the email or while preparing API url ?

Hi @dhiraj.star,

Welcome to the Auth0 Community!

I understand that you’ve been getting 400 bad request errors when calling the get users by email endpoint.

After looking at your error, it appears that the email format passed in the request is not in the correct format.

The actual value passed was testUser1%2Bsan1%40gmail.com, but the expected value is testUser1+san1@gmail.com instead. The email property expects a string.

Given that, could you please try passing the user’s email address without encoding?

Please let me know if this resolves your issue.

Thank you.

Hey @rueben.tiow

Thanks for reply, If I pass the email without encoding then error message is :slight_smile:

400 Bad Request: [{“statusCode”:400,“error”:“Bad Request”,“message”:“Query validation error: ‘Object didn’t pass validation for format email: testUser1 san1@gmail.com’ on property email (Email address to search for (case-sensitive)).”,“errorCode”:“invalid_query_string”}]

Whenever i user an email address with ‘+’ character in it. AUth0 while logging in replaces it with ’ '(space) and return that the email validation fails hence no user was found?

If I use implementation group: ‘com.mashape.unirest’, name: ‘unirest-java’, version: ‘1.4.9’
to make api calls to Auth0 then it worked like this
HttpResponse response = Unirest.get(url)
.headers(httpHeaders).asJson();

It only give error when I use spring boot RestTemplate to make API calls
restTemplate.exchange(uri.toString(), HttpMethod.GET, entity, String.class);

1 Like