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
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,646 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Srinivasa Rao Darna 6,691 Reputation points Microsoft Vendor
    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".