I need to perform an OData query $search = "subject:pizza" using the OutLook 365 API but using the Outlookservicesclient (found the in the outlook 365 sdk, this nuget https://www.nuget.org/packages/Microsoft.Office365.OutlookServices-V2.0/)
See this OutLookAPI OData query Reference
This works correctly using an HttpClient but with the .NET client library, its seemingly not possible to add any non-standard query parameters.
Ie: var messages = await client.Users['mail@me.com'].Messages
.Where(m => m.IsRead == false)
.Take(50)
.ExecuteAsync();
Produces the following RequestURI https://outlook.office365.com/api/v2.0/Users('mail%40me.com')/Messages?$filter=IsRead eq false&$top=50
And executes correctly.
Whereas if try the following, var query = client.Users['Mail@me.com'].Messages
.Context.CreateQuery<Message>("Users('Mail@me.com')/Messages")
.AddQueryOption("$search", "subject:pizza");
Either returns Exception:Thrown: "Can't add query option '$search' because it begins with reserved character '$'." (System.NotSupportedException) A System.NotSupportedException was thrown: "Can't add query option '$search' because it begins with reserved character '$'."
or im getting authentication errors if I omit the AddQueryOption line.
All I need to do as append $search=subject:pizza
the RequestURI! This seems impossible without actually using a rest client as the Outlook Client seems limited to built in Linq methods.
Added the fact there is no reference documentation for the client library, ive hit a dead end. Does anyone know if its possible to include $search via the outlookservicesclient?
I checked with the OData.NET folks, and they've opened an issue on GitHub to track the error adding
$search
withAddQueryOption
. In the meantime, they suggested you could try something like this to make it work: