Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Microsoft Graph client sdk how would you use search Odata query

Using Microsoft Graph client sdk how would one go about using search Odata query to lookup if subject or body contains a certain search term.

The $search Odata query parameter is available in the Graph Client api, but i could not find how to use the parameter using the client sdk for c#.

like image 941
John Staurt Avatar asked Jul 08 '17 15:07

John Staurt


People also ask

How do I get data from Microsoft Graph API?

You can access Graph Explorer at: https://developer.microsoft.com/graph/graph-explorer. You can either access demo data without signing in, or you can sign in to a tenant of your own.

What is Microsoft Graph used for?

Microsoft Graph is the gateway to data and intelligence in Microsoft 365. It provides a unified programmability model that you can use to access the tremendous amount of data in Microsoft 365, Windows, and Enterprise Mobility + Security.


2 Answers

You can add any query parameters by passing in a list of QueryOptions to the Request method.

List<QueryOption> options = new List<QueryOption>
{
     new QueryOption("$search", "lunch")
};
var messages = await client.Me.Messages.Request(options).GetAsync();

Documentation: https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/dev/docs/overview.md#custom-query-options

like image 198
David Avatar answered Sep 29 '22 18:09

David


Piggybacking off of @JohnStaurt's comments above, this worked for me:

List<QueryOption> options = new List<QueryOption>
{
     new QueryOption("$search", "\"displayName:team\" OR \"description:team\"")
};
like image 39
Tracy Avatar answered Sep 29 '22 18:09

Tracy