'MS Teams Graph API: Get all teams user(s) are apart of

I want to use the graph api to get the teams a list of users is a member/owner of. I am using this endpoint to pass the list of users, then select the properties of the group that I am interested in:

/beta/users/$filter=id+in+('user-1','user-2','user-15')$expand=transitiveMemberOf($select=id,resourceProvisioningOptions,displayName,mailNickname)&$select=id,resourceProvisioningOptions,displayName

This will return a list of groups the member is apart of, including the Teams the member is apart of (up to 15 users). It will filter the groups to only return id,resourceProvisioningOption,displayName and mailNickname.

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users(id,resourceProvisioningOptions,displayName,transitiveMemberOf(id,resourceProvisioningOptions,displayName,mailNickname))",
    "value": [
        {
            "id": "user-1",
            "displayName": "Jeff Smith",
            "transitiveMemberOf": [
                {
                    "@odata.type": "#microsoft.graph.directoryRole",
                    "id": "directoryRole-1",
                    "displayName": null
                },
                {
                    "@odata.type": "#microsoft.graph.directoryRole",
                    "id": "directoryRole-2",
                    "displayName": null
                },
                {
                    "@odata.type": "#microsoft.graph.group",
                    "id": "team-id-1",
                    "resourceProvisioningOptions": [
                        "Team"
                    ],
                    "displayName": "My Team 1",
                    "mailNickname": "MyTeam1"
                },
                {
                    "@odata.type": "#microsoft.graph.directoryRole",
                    "id": "directoryRole-3",
                    "displayName": null
                },
                {
                    "@odata.type": "#microsoft.graph.group",
                    "id": "team-id-2",
                    "resourceProvisioningOptions": [
                        "Team"
                    ],
                    "displayName": "My Team 2",
                    "mailNickname": "MyTeam2"
                }
            ]
        }
    ]
}

Since the user is apart of Azure directory groups, those are returned, but the resourceProvisioningOptions identifies if the user is on a team. In this case - 2 teams.

Problem

When looking in the Teams App, we see that the user is actually apart of the 10 different teams.

When calling this endpoint: https://graph.microsoft.com/v1.0/users/user-1/joinedTeams we see that the user is apart of 10 teams

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#teams",
    "@odata.count": 10,
    "value": [
        {
            "id": "team-id-1",
            "createdDateTime": null,
            "displayName": "Team 1",
            "description": "Team1",
            "internalId": null,
            "classification": null,
            "specialization": null,
            "visibility": null,
            "webUrl": null,
            "isArchived": false,
            "isMembershipLimitedToOwners": null,
            "memberSettings": null,
            "guestSettings": null,
            "messagingSettings": null,
            "funSettings": null,
            "discoverySettings": null,
            "summary": null
        },
        {
            "id": "team-id-2",
            "createdDateTime": null,
            "displayName": "Team 2",
            "description": "Team2",
            "internalId": null,
            "classification": null,
            "specialization": null,
            "visibility": null,
            "webUrl": null,
            "isArchived": false,
            "isMembershipLimitedToOwners": null,
            "memberSettings": null,
            "guestSettings": null,
            "messagingSettings": null,
            "funSettings": null,
            "discoverySettings": null,
            "summary": null
        },
        ...
        {
            "id": "team-id-10",
            "createdDateTime": null,
            "displayName": "Team 3",
            "description": "Team3",
            "internalId": null,
            "classification": null,
            "specialization": null,
            "visibility": null,
            "webUrl": null,
            "isArchived": false,
            "isMembershipLimitedToOwners": null,
            "memberSettings": null,
            "guestSettings": null,
            "messagingSettings": null,
            "funSettings": null,
            "discoverySettings": null,
            "summary": null
        }
    ]
}

Questions:

  1. Is there another endpoint that I can use to pass a list of users and get the teams they are owner/member of?
  2. Why is the data different between endpoints

I am trying to avoid calling the /joinedTeams endpoint due to number of users and rate limiting.



Solution 1:[1]

You could use the /joinedTeams endpoint, but also put those calls in a batch to MS Graph.

See: https://docs.microsoft.com/en-us/graph/json-batching

This would allow you to send a batch of 20 (i think) requests in one call to the graph making it much faster and less likely to be throttled.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Chris Johnson