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
2022-11-15T12:09:00.343+00:00

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

sub="attach";
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()  
	    .buildRequest()  
	    .top(1000)  
	    .count(true)  
	    .get();
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
    2022-11-15T16:55:35.437+00:00

    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 = graphClient.me().messages()  
    	.buildRequest( requestOptions )  
    	.filter("subject eq 'test'")  
    	.get();  
    

    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".