1

I could get all site (including root level site as well as sub site) by using the following url : https://graph.microsoft.com/v1.0/sites?search=*

Is there a better way to get all the root level sites only (excluding the sub site) using Microsoft Graph API ?

1

Microsoft Graph documentation says the following filter expression could be utilized to list all root-level site collections:

siteCollection/root ne null

But unfortunately i have not managed to get it working against V1 endpoint. As a workaround you could consider to filter root-level site collections on the client side, here is C# example (utilizes Microsoft Graph Client Library for .NET):

var result = new List<Microsoft.Graph.Site>();
var requestUrl = "https://graph.microsoft.com/v1.0/sites?search=*&select=webUrl,siteCollection";
var message = new HttpRequestMessage(HttpMethod.Get, requestUrl);
await graphClient.AuthenticationProvider.AuthenticateRequestAsync(message);
var response = await graphClient.HttpProvider.SendAsync(message);

var content = await response.Content.ReadAsStringAsync();
var sites = JsonConvert.DeserializeObject<List<Microsoft.Graph.Site>>(JObject.Parse(content)["value"].ToString());
result = sites.Where(s => s.SiteCollection != null).ToList();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.