Search using Graph SDK not working, unable to find GeoLocation code.

Parth Jani 90 Reputation points
2023-07-18T13:23:05.0533333+00:00

Hello,

I am trying to use Search using Graph sdk 5.x.

I am able to fetch search results given that i pass region.
But i am not able to fetch region dynamically.
SiteCollection resource has datlocationcode null for single geo tenant.
https://learn.microsoft.com/en-us/graph/api/resources/sitecollection?view=graph-rest-1.0
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/multigeo-discovery
as mentioned in above link.

->I have also tried with graphClient.Organization , it doesnt have geo location.
->Also i have tried to give delegate permission for file.readall ,site.readall, search.config but the below code does't work without region and i am not able to fetch region dynamically.

->What i want is to fetch region dynamically or make work below code without using region.

Please help.

Please refer below code :

   SearchRequest request = new SearchRequest();
                string searchTerm = "test path:\"https://obscurepi.sharepoint.com/sites/SiteInfi2022\" AND candlelight";
                SearchQuery query = new SearchQuery();
                query.QueryString = searchTerm;
                List<EntityType?> entityType = new List<EntityType?>();
                entityType.Add(EntityType.DriveItem);
                entityType.Add(EntityType.ListItem);
                entityType.Add(EntityType.List);

                Dictionary<string, object> keyValues = new Dictionary<string, object>();
                keyValues.Add("region", "IND");
               

                request.Query = query;
                request.EntityTypes = entityType;
                //request.AdditionalData = keyValues;

                QueryPostRequestBody qprb = new QueryPostRequestBody();
                 qprb.AdditionalData = keyValues;

                qprb.Requests = new List<SearchRequest> { request };


                var result1 = GraphClient.Search.Query.PostAsync(qprb).Result;
Microsoft 365 and Office SharePoint Development
Microsoft 365 and Office SharePoint For business Windows
Developer technologies .NET Other
Microsoft Security Microsoft Graph
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2023-07-19T08:31:10.3866667+00:00

    Hi @Parth Jani,

    You can register app-only authentication to access graph api. Get an app-only access token and use it for authentication. Please refer to the following document

    https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly


    If the answer is helpful, 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.


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.