microsoft-graph-apisharepoint-onlinemicrosoft-graph-teams

How to determine associated Sharepoint site collections of a team/group?


I'm using Microsoft 365 and Teams. I need to check the rights of users in a team in MS Teams and in addition given access to files / folders within the folder structure as well.

My first approach was to use the graph sdk. I can access the group and associated team using:

var groups = await graphClient.Groups.GetAsync(x =>
    {
        x.QueryParameters.Filter = "displayName eq 'MyTeam'";
    });
var group = groups.First();
var team = await graphClient.Groups[group.Id].Team.GetAsync();

Now I want to determine the site collection and to access it as well to check the members and user rights there.

I used

var associatedSites = await graphClient.Groups[group.Id].Sites.GetAsync();

but I get all sites and not just those of the team.

So how can I get access to the associated site collection and the associated folder structure to check the members and their rights.


Solution

  • The graph api has this endpoint GET /groups/{group-id}/sites/root. See in the api reference.

    So this should work:

    var site = await graphClient.Groups[groupId].Sites["root"].GetAsync();