How to pass the region on Graph SDK Search method

Tim Tegenbosch 20 Reputation points
2024-08-16T07:19:03.77+00:00

I am currently working on a WinForms application that interacts with our SPO environment, using the Graph SDK. The application is written in .NET 4.7.2, and uses the “Microsoft.Graph” (SDK) 4.19.0.

Simplified code:

Dim srObject As New SearchRequestObject()
srObject.Query = New SearchQuery()
srObject.EntityTypes = New List(Of EntityType) From {EntityType.DriveItem}
srObject.Query.QueryString = String.Format("{0} AND isDocument=True", searchValue)

Dim lstSearchQueryOptions As New List(Of SearchRequestObject)()
lstSearchQueryOptions.Add(srObject)

Dim responsePage = Await _graphClient.Search.Query(lstSearchQueryOptions).Request().PostAsync()

If (Not responsePage Is Nothing) AndAlso (Not responsePage.CurrentPage Is Nothing) Then
	...
End If

In order to perform the needed tasks, our Azure AD application has been given the needed “Application permissions”. However, I keep getting the following error when executing the Search Query:

Status Code: BadRequest
Microsoft.Graph.Service Exception: Code: BadRequest
Message: SearchRequest Invalid (Region is required when request with application permission.)
Details: Detail0: Code: Microsoft.SubstrateSearch.Api.ErrorReporting.ResourceBasedExceptions.BadRequestException
Message: Region is required when request with application permission.
AdditionalData: httpCode : 400

I can’t seem to find any property to add the “Region” information on the request.
Is there any way to add this property? Or otherwise, any way to resolve this issue?

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,834 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,989 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,722 questions
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 31,166 Reputation points Microsoft Vendor
    2024-08-19T02:34:56.14+00:00

    Hi @Tim Tegenbosch ,

    As of the version you're using (4.19.0), the SearchRequestObject does not have a direct property to specify the "Region."

    Try updating to a newer version of the Microsoft Graph SDK that support this functionality directly.

    Best Regards.

    Jiachen Li


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Tim Tegenbosch 20 Reputation points
    2024-08-27T12:24:30.8333333+00:00

    Jiachen Li-MSFT,

    I upgraded the reference to version 4.54.0, the latest version that is supported for .NET framework.
    In this version the property "Region" is present.

    Thank you for the help

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.