How to count sharepoint sites

Maxime Clavel 0 Reputation points

Here is our current code in Go (GoLang) using the msgraph-sdk-go: pkg:

func (me *graphClient) SitesCount(ctx context.Context) (int64, error) {
 	siteRequester := me.graphSdkClient.Sites()

  	headers := abstractions.RequestHeaders{}
 	headers.Add("ConsistencyLevel", "eventual")

  	displayCount := true
 	top := int32(0)

  	config := &sites.SitesRequestBuilderGetRequestConfiguration{
 		QueryParameters: &sites.SitesRequestBuilderGetQueryParameters{
 			Count: &displayCount,
 			Top:   &top,
 		Headers: &headers,

  	req, err := siteRequester.Get(ctx, config)
 	if err != nil {
 		return 0, err

  	totalCount := req.GetOdataCount()
  	return *totalCount, nil

HTTP API call:


This returns the count of sites (SharePoint and personal/OneDrive).

We would like to get the count of SharePoint sites only (without personal/OneDrive).

We saw the additionalData field where isPersonal=true. Can we use this field? If yes, how?

Summary: How can we get the count of SharePoint sites in one call without iterating on every sites?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,839 questions
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,865 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 32,166 Reputation points Microsoft Vendor

    Hi @Maxime Clavel,

    Per my research, currently we are unbale to filter the site by isPersonal properties. As a workaround, I would recommend you to use graph search to get the sharepoint site. Since the url of OneDrive starts with, and the url of SharePoint site starts with So you could add filter in th query like this to ignore Onedrive site:



    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.