Search code examples
microsoft-graph-apiazure-ad-graph-apimicrosoft-graph-sdksmicrosoft-graph-teams

Graph API for accessing teams and team's groups to pull documents


I am working on asset management system in which my application needs to pull specific documents of all the employees being stored by them on teams or any teams group. Using graph API or any other medium, how can I achieve the same. Any suggestions or pointers will be helpful to start with.


Solution

  • Teams has a associated Group.

    So you need to get the list of all the Teams first through (reference):

    GET https://graph.microsoft.com/beta/groups?$filter=resourceProvisioningOptions/Any(x:x eq 'Team')
    

    Then you can traverse this list to get the Group (Teams) id.

    Get the channels in an Teams like this (reference):

    GET https://graph.microsoft.com/v1.0/teams/{Group id}/channels
    

    Record the channels' name.

    Now use this call to get the files stored in a Teams channel (reference):

    GET https://graph.microsoft.com/v1.0/groups/{Group id}/drive/root:/{channel name}:/children
    

    You need to implement multiple loops to get all the files stored in Teams.

    UPDATE:

    Using the following request to list the items in the Teams:

    GET https://graph.microsoft.com/v1.0/groups/{Group id}/drive/root/children
    

    You can get the item id of General folder from the response.

    Then you can get the files under General folder through:

    GET https://graph.microsoft.com/v1.0/groups/{Group id}/drive/items/{item id}/children