SearchAlterationOptions in a Microsoft Graph Search Request not working

69 Views Asked by At

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

1

There are 1 best solutions below

3
On

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);