Graph Api for SharePoint online returns empty hits

ברק זאובר 1 Reputation point
2022-02-17T08:46:09.24+00:00

Hello,

I'm using microsoft graph to query document libraries on my SharePoint Online site.

I'm querying managed property.

When I tested it on Graph explorer - I got result with hits that contained the actual file that has this managed property.

When I tried to develop it - I got result that matched the graph explorer - but the hit section was empty [[{}, {}]

Here's the data I'm using in Graph explorer:

{
"requests": [
{
"entityTypes": [
"driveItem"
],
"query": {
"queryString": "RefinableString01:'555555'"
}
}
]
}

and here's the code I'm using:
GraphServiceClient client = GetAuthenticatedGraphClient(userName, userPassword);
var searchRequest = new
{
requests = new[]
{
new
{
entityTypes = new[] {"microsoft.graph.driveItem"},
query = new
{
query_string = new
{
query = "RefinableString01:'555555"
}
}

}
}
};
//construct a request

var message = new HttpRequestMessage(HttpMethod.Post, "https://graph.microsoft.com/v1.0/search/query");
var jsonPayload = client.HttpProvider.Serializer.SerializeObject(searchRequest);
message.Content = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
await client.AuthenticationProvider.AuthenticateRequestAsync(message);
var response = await client.HttpProvider.SendAsync(message);
//process response
var content = await response.Content.ReadAsStringAsync();
var result = JObject.Parse(content);

This is the result I'm getting:

{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.searchResponse)","value":[{"searchTerms":[],"hitsContainers":[{"total":2,"moreResultsAvailable":false,"hits":[{}]}]}]}

I have all the permissions in Azure - the same as in Graph Explorer and more - but still it doesn't work

Does anybody have any idea why this is hapenning?
Thanks,
Barak

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,874 questions
0 comments No comments
{count} votes