Search code examples
c#microsoft-graph-apimicrosoft-graph-sdksmicrosoft-graph-teams

How do I get all Teams in MS Graph C#?


I have created a Team in the group successfully, now I need to cycle through the Teams so I can get their names and IDs.

I have tried the following code but without any success.

IGraphServiceTeamsCollectionPage teams = graphServiceClient
    .Teams
    .Request()
    .GetAsync()
    .Result;

foreach (Team team in teams)
{
    Console.WriteLine(team.Id);
}

I get

Code: UnknownError
Message: 
{
    "message":"No HTTP resource was found that matches the request URI 'https://api.teams.skype.com/v1.0/teams'."
}

I've also tried doing the same against Groups without success:

var groups = await graphServiceClient.Groups
    .Request()
    .GetAsync();

foreach (var group in groups)
{
    Console.WriteLine(group.DisplayName);
    Console.WriteLine(group.Team.Id);
}

Now I get the displayName of the Group, but when trying to access the Group's Team Id I get

Object reference not set to an instance of an object.

EDIT:

I have realized that Group ID = Teams ID, however, last week I was able to update the specific team with the following command:

await graphServiceClient
    .Teams[groupID]
    .Request()
    .UpdateAsync(team3);

but now it does not work and says:

No team found with Group Id {9032fa63-50bb-4....}

I have confirmed in PowerShell and Graph Explorer, that the Id is correct and, as I've said, it worked on Friday of last week.


Solution

  • I am using the groupID which is equal to teamID.

     var groups = await graphServiceClient.Groups.Request().GetAsync();
     foreach (var group in groups)
     {
       Console.WriteLine(group.DisplayName);
       Console.WriteLine(group.Id);
     }