I have the following code in C# to make a graph call:
public async Task<IGraphServiceUsersCollectionPage> GetResponseAsync(string s)
{
var queryOptions = new List<QueryOption>()
{
new QueryOption("$count", "true"),
new QueryOption("$search", "")
};
return await graphServiceClient
.Users
.Request(queryOptions)
.Header("ConsistencyLevel", "eventual")
.Filter("")
.Select("")
.OrderBy("")
.GetAsync();
});
}
an example of string s is "https://graph.microsoft.com/v1.0/users?$count=true&$search="displayName:room"&$filter=endsWith(mail,'microsoft.com')&$orderBy=displayName&$select=id,displayName,mail"
how do I parse this string so that I can pass:
displayName:room as Search value
endsWith(mail,'microsoft.com') as Filter value
displayName and OrderBy value
id,displayName,mail as Select value
to the code?
public async Task<IGraphServiceUsersCollectionPage> GetResponseAsync(string s)
{
var queryOptions = new List<QueryOption>()
{
new QueryOption("$count", "true"),
new QueryOption("$search", "\"displayName:room\"")
};
return await _graphServiceClient
.Users
.Request(queryOptions)
.Header("ConsistencyLevel", "eventual")
.Filter("endsWith(mail,'microsoft.com')")
.Select("id,displayName,mail")
.OrderBy("displayName")
.GetAsync();
}
UPDATE:
Same for places, here is what I have tried based on the answer below:
var queryParamValues = HttpUtility.ParseQueryString(url, Encoding.UTF8);
var filterValue = queryParamValues["$filter"];
var selectValue = queryParamValues["$select"];
var queryOptions = new List<QueryOption>() { new QueryOption("$count", "true") };
var roomUrl = _graphServiceClient.Places.AppendSegmentToRequestUrl("microsoft.graph.room");
var request = new GraphServicePlacesCollectionRequest(roomUrl, _graphServiceClient, queryOptions);
if (!string.IsNullOrEmpty(filterValue)) { request = (GraphServicePlacesCollectionRequest)request.Filter(filterValue); }
if (!string.IsNullOrEmpty(selectValue)) { request = (GraphServicePlacesCollectionRequest)request.Select(selectValue); }
return await request
.Top(MaxResultCount)
.GetAsync();