Unable to retrieve all of the active sites in a Microsoft 365 tenant using GetAllSites

Rahul Verma 0 Reputation points
2024-07-18T11:36:56.8966667+00:00

I am currently trying to retrieve all of the sites in a tenant using the method below. I am currently using the beta API, but I have also tried using the v1.0 API as well. I have all of the required permissions assigned to the app being, Sites.ReadWrite.All.

Currently I am getting on some of the sites but not all of them,

public static async Task<string> GetAllSitesAsync()
    {
        //21 sites to fetch
        if (!isInitialised)
        {
            throw new InvalidOperationException("APICaller is not initialised. Call Initialise method first.");
        }

        try
        {
            
            var sites = await graphHandler.GraphClient.Sites.GetAllSites.GetAsGetAllSitesGetResponseAsync();

            var options = new JsonSerializerOptions
            {
                WriteIndented = true
            };
            var json = JsonSerializer.Serialize(sites, options);
                
            return json;
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Exception: {ex.Message}");
            return string.Empty;
        }
    }


I have also tried to use

var result = await graphClient.Sites.GetAsync((requestConfiguration) =>
{
	requestConfiguration.QueryParameters.Select = new string []{ "*" };
});

Which again returns some sites that are not previously returned. But also some sites are not returned in either.

Any help would be kindly appreciated.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,618 questions
0 comments No comments
{count} votes