Finding the Files location of Microsoft Teams Channel using the Microsoft Graph

You may have come across the Files tab for a channel in Microsoft Teams.


This basically shows the contents of a folder inside a Document Library in a SharePoint Team Site, the one that is provisioned when the Team was first created.


In that Files tab, you are able to open that location by clicking “Open in SharePoint”

/media/2018/08/2018-08-22_23-20-22.png But, determining this location programmatically can be a bit tricky. You see; the Microsoft Graph Beta API has a call to find the list of channels in a Microsoft Team:{team-id}/channels

You can even get a call to get the channel info:{team-id}/channels/{channel-id}

But currently, there is no call to get the URL of a channel’s files. Personally, I would find it very useful if the following call was possible:{team-id}/channels/{channel-id}/drive

(so I have put some feedback in UserVoice) Or, if the call to get channel info returned the webUrl, like it does in the Drive resources (with the corresponding UserVoice feedback).

We can do something

What we do have available though, is the ability to use the {team-id} in a call to get a group’s drive items.{team-id}/drive/root/children

/drive/root will bring forward the Document Library that the channel folders are in, and /children will display all the items in that folder. This is not to say that everything in there is a channel folder or even related to Teams, as the location we are looking at is a fully-featured SharePoint Team Site, anyone could be storing documents in that Library, and creating folders. Visibly there is no difference between a folder representing a Team Channel and a User-created folder. Therefore, we will need to iterate through each child and find the ones that are. What you are looking for is who created the item, it should look like the one below.

"createdBy": {
  "application": {
    "id": "cc15fd57-2c6c-4117-a88c-83b1d56b4bbe",
    "displayName": "Microsoft Teams Services"

It seems obvious from the displayName that Teams has created it, but do not use that for comparison. I have also seen “Skype Team Services” for the displayName in cases when Teams was a relatively new product. Stick to using the id, that has not changed and we have no guarantee that the displayName will not change in the future. Unfortunately, the call mentioned above does not allow for odata filtering so you will need to return the full payload and filter yourself.

This isn’t exactly perfect

In the payload returned, you are also given a webUrl that displays the SharePoint location of the Files of that Team Channel. You may also see that it gives you the name of the folder as well. One thing to point out is if you change the name of a channel, the change is not reflected in SharePoint, so the name and webUrl remain as the original.

If you rename the “foo” channel to “bar”, the change is visible in teams but the files are still located in the “foo” folder on the SharePoint Team site.

This is not always a problem, but it does provide no way to exactly know what a channel is actually named, only what it was originally named. There are already two requests for the change to be reflected in SharePoint; one in the Microsoft Teams UserVoice, and the other in the SharePoint UserVoice.

There is hope

As the Teams component of the Graph API is still in Beta, the Graph team are keen to know what they can do to improve the calls. As such, I am hoping the feedback I have added to UserVoice will be seen and added before the calls leave Beta.