1

I'm trying to add logic to my c# function app that does something similar to this test query I tried in Graph Explorer:

enter image description here

This is the response I get back (notice that it automatically fixed my typo and ran the search)

enter image description here

I'm trying to do this programmatically in c# but it doesn't correct my spelling. This is what my c# code looks like in part:

         var requestBody = new Microsoft.Graph.Search.Query.QueryPostRequestBody
            {
                Requests = new List<SearchRequest>
                    {
                        new SearchRequest
                        {
                            EntityTypes = new List<EntityType?>
                            {
                                EntityType.DriveItem,
                            },
                            Query = new SearchQuery
                            {
                                QueryString = this.searchQuery,
                            },
                            Fields = new List<string>
                            {
                                "listId",
                                "author",
                                "title",
                            },
                            QueryAlterationOptions = new SearchAlterationOptions
                            {
                                EnableSuggestion = true,
                                EnableModification = true,
                            },
                            Region ="US"
                        },
                    },
            };

            var result = await graphClient.Search.Query.PostAsync(requestBody);

This is a screenshot of what I get back when I send this query to my app via postman:

enter image description here

I get an error that looks like this:

enter image description here

EDIT 1

Trying "NAM" for the region gives me this error:

enter image description here

dot
  • 14,928
  • 41
  • 110
  • 218
  • Why do you have to specify a region at all? In your graph explorer request screenshot it is also not specified and it seems to return something meaningful. Maybe open dev tools and check within the network tab what's really on the wire. Maybe there is some additional request header or similar that's missing in the SDK call. – Oliver Jul 24 '23 at 13:04
  • Do you use the same token in SDK and Graph explorer? Or at least the same user? Or do you use in your SDK an app token, while in Graph explorer a user token is in place? – Oliver Jul 24 '23 at 13:06
  • Good question, @Oliver. So in my demo app i'm using an app registration. but in graph, i've authenticated as myself - as a user. in the app, it forces me to specify a region. I can't run the code without it. – dot Jul 24 '23 at 15:14
  • What i've noticed is that in Graph Explorer version 1, the typing mistakes are auto corrected. But in code, using the same version of the API, they do not auto correct. Also, no matter what search I execute in code, I always have to have Region =US in order for anything to work. Otherwise, I get the error saying that I'm missing the region value. The difference between my code / project and Graph Explorer, is as @Oliver aptly pointed out, I'm using an app registration in my code vs. my user credentials in graph – dot Jul 24 '23 at 18:12
  • While this won't help you to solve this issue, I would guess if you use a user token in your code you won't need to specifiy a region and the answer would be the same as in the graph explorer. I think to solve the issue and get the expected behaviour also with an app token you'll have to open a technical support request in the azure portal. – Oliver Jul 25 '23 at 07:25

1 Answers1

0

It seems to me that the value US of the region property is not correct. Possible values for the region property are:

Code Geo location
APC Macro Region Geography 2 - Asia-Pacific
AUS Australia
BRA Brazil
CAN Canada
EUR Macro Region Geography 1 - EMEA
FRA France
DEU Germany
IND India
JPN Japan
KOR Korea
NAM Macro Region Geography 3 - Americas
NOR Norway
QAT Qatar
POL Poland
ZAF South Africa
SWE Sweden
CHE Switzerland
ARE United Arab Emirates
GBR United Kingdom

Try to use one of the value above

var requestBody = new Microsoft.Graph.Search.Query.QueryPostRequestBody
        {
            Requests = new List<SearchRequest>
                {
                    new SearchRequest
                    {
                        EntityTypes = new List<EntityType?>
                        {
                            EntityType.DriveItem,
                        },
                        Query = new SearchQuery
                        {
                            QueryString = this.searchQuery,
                        },
                        Fields = new List<string>
                        {
                            "listId",
                            "author",
                            "title",
                        },
                        QueryAlterationOptions = new SearchAlterationOptions
                        {
                            EnableSuggestion = true,
                            EnableModification = true,
                        },
                        Region ="NAM"
                    },
                },
        };

        var result = await graphClient.Search.Query.PostAsync(requestBody);
user2250152
  • 14,658
  • 4
  • 33
  • 57
  • ah ok I'll give this a try. but can you tell me where you got this list from? maybe a link to a ms doc? please and thanks – dot Jul 23 '23 at 18:28
  • @dot https://learn.microsoft.com/en-us/microsoft-365/enterprise/multi-geo-ediscovery-configuration?view=o365-worldwide – user2250152 Jul 24 '23 at 05:15
  • please see EDIT 1. It's actually saying the only valid region is US. – dot Jul 24 '23 at 12:49