How to pass searchstring in variable to search on messages for Subject,From,From date using MS Graph Api in java?

B Jayachithra 1 Reputation point

Tried below query to search subject contains attach ,but filter is not applied correctly and all messages are listed

LinkedList<Option> requestOptions = new LinkedList<Option>();
requestOptions.add(new HeaderOption("ConsistencyLevel", "eventual"));
requestOptions.add(new QueryOption("$filter=subject eq", sub));

	MessageCollectionPage messages = _appClient.users(user).mailFolders(folder).messages()  
Microsoft Graph Files API
Microsoft Graph Files API
A Microsoft API to create an app that connects with files across OneDrive, OneDrive for Business, and SharePoint document libraries.
351 questions
Microsoft Graph Search API
Microsoft Graph Search API
A Microsoft API that searches for information in email messages, returns messages ranked by relevance, and renders a dedicated search experience.
174 questions
Microsoft Graph SDK
Microsoft Graph SDK
A Microsoft software developer kit designed to simplify building high-quality, efficient, and resilient applications that access Microsoft Graph.
882 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Srinivasa Rao Darna 6,461 Reputation points

    Hi @B Jayachithra ,

    Please find below sample snippet using Java for Microsoft Graph with GET /me/messages?$filter=subject eq 'test'.

    LinkedList<Option> requestOptions = new LinkedList<Option>();  
    requestOptions.add(new HeaderOption("Prefer", "outlook.body-content-type=\"text\""));  
    MessageCollectionPage messages =  
    	.buildRequest( requestOptions )  
    	.filter("subject eq 'test'")  

    Hope this helps.
    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".