mail search not working

Nagarajan, Divya (External) 41 Reputation points
2022-12-05T19:30:07.03+00:00

Im using below java code to getuser by email.

UserCollectionPage users = graphClient.users().buildRequest()
.filter("eq(mail,'XXXXX@mailinator.com')") // not working bad request
.get();

Error Msg:
Throwable detail: com.microsoft.graph.http.GraphServiceException: Error code: BadRequest
Error message: Invalid filter clause

GET https://graph.microsoft.com/v1.0/users?%24filter=eq%28mail%2C%27XXXXX%40mailinator.com%27%29
SdkVersion : graph-java/v5.9.0

400 : Bad Request
[...]

[Some information was truncated for brevity, enable debug logging for more details]
2022-12-06 00:55:36.132 ERROR 8148 --- [nio-8090-exec-2] u.c.k.x.c.advice.XeroxExceptionHandler : Exception

com.microsoft.graph.http.GraphServiceException: Error code: BadRequest
Error message: Invalid filter clause

GET https://graph.microsoft.com/v1.0/users?%24filter=eq%28mail%2C%27xxxxxx%40mailinator.com%27%29
SdkVersion : graph-java/v5.9.0

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,569 questions
Microsoft Entra External ID
Microsoft Entra External ID
A modern identity solution for securing access to customer, citizen and partner-facing apps and services. It is the converged platform of Azure AD External Identities B2B and B2C. Replaces Azure Active Directory External Identities.
2,639 questions
0 comments No comments
{count} votes

Accepted answer
  1. CarlZhao-MSFT 36,891 Reputation points
    2022-12-06T03:05:01.553+00:00

    Hi @Nagarajan, Divya (External)

    Your $filter query parameter format is wrong, the correct filter should be:

    https://graph.microsoft.com/v1.0/users?$filter=mail eq 'XXXXX@mailinator.com'  
    

    The graph java sdk:

    GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();  
      
    UserCollectionPage users = graphClient.users()  
    	.buildRequest()  
    	.filter("mail eq 'XXXXX@mailinator.com'")  
    	.get();  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Nagarajan, Divya (External) 41 Reputation points
    2022-12-13T15:26:16.467+00:00

    The solution mentioned here is working.
    Thank you @CarlZhao-MSFT

    0 comments No comments