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 Answer 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();
  • Sadly I havent been able to run on the beta endpoint the /sites?$filter=siteCollection/root ne null as documented, gives me very different results compared to the one that you suggest on the v1.0 endpoint. Mar 21, 2020 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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