msgraph-sdk-dotnet icon indicating copy to clipboard operation
msgraph-sdk-dotnet copied to clipboard

Microsoft Graph Search API using Azure key vault?

Open ward-horsfall opened this issue 2 years ago • 2 comments

Hi.

How can I use the Microsoft Graph search API using C# to connect via Azure Key Vault?

(I want to be able to search email messages)

Is the a C# sample I can look at.

Thanks Ward

ward-horsfall avatar Oct 10 '22 15:10 ward-horsfall

Thanks for raising this @ward-horsfall

You can perform a search query with an example as below in line with the documentation at https://learn.microsoft.com/en-us/graph/search-concept-messages

  var searchRequests = new List<SearchRequestObject> 
  {
      new SearchRequestObject
      {
         EntityTypes = new List<EntityType>
         {
             EntityType.Message
         },
         Query = new SearchQuery
         {
             QueryString = "contoso"
         },
         From = 0,
         Size = 25
      }
  };

  await graphClient.Search
  .Query(searchRequests)
  .Request()
  .PostAsync();

With regards to Azure KeyVault, are you looking to just fetch a secret from it?

andrueastman avatar Oct 14 '22 07:10 andrueastman

Hi andrueastman,

Thanks for your response.

Yes correct it is how to fetch a secure from it (via Azure KeyVault).

After that then make a connection to it - to create an instance of graphClient that I can use in your example.

Thanks again,

Ward

ward-horsfall avatar Oct 14 '22 07:10 ward-horsfall