Get a Teams channel SharePoint Url using Graph API

Microsoft Teams uses SharePoint online to store the files for a Team. Each channel in a Team is a folder in the ‘Documents’ library in the SharePoint site collection for the Team.

folders

The problem we currently have is for renamed Channels, the underlying folder stays with the original name in the document library in SharePoint so there is a disassociation between the two which leads to great confusion for users. One of the most requested features in the Graph API user voice is to remedy this situation to have the two in sync and at the time of writing it is currently being worked on.

Sometimes it is necessary to access the underlying SharePoint object that represents the Channel folder in SharePoint to perform specific SharePoint operations. You can get the SharePoint url of the Team by accessing the Graph API at https://graph.microsoft.com/v1.0/groups/<TeamId>/sites/root/webUrl

site url graph

As mentioned previously, renamed channels stay with the original foldername so you cannot rely on the name of the channel to construct a Url to the channel folder in SharePoint. If the channel has never been renamed the following would work but this would not work for renamed channels or private channels:

<TeamWebUrl>/Shared Documents/<ChannelName>

e.g. https://testsite.sharepoint.com/sites/team1/Shared Documents/General

Thankfully, new channel properties have been added under the Beta endpoint of the Graph API to give us the underlying SharePoint Url for a channel in Teams. This allows us to always reliably get to the folder in SharePoint. The endpoint is:

https://graph.microsoft.com/beta/teams/<TeamId>/channels/<channelId>/filesFolder

fileFolder

You can access the documentation here.

The webUrl property stores the url of the folder in SharePoint. This is also very useful for navigating to Private channels in SharePoint which are hosted in their own dedicated site collection just for hosting the private channel folder.

This nows gives us API access to Teams Channels and SharePoint folders using the Graph API so now regardless of whether the channel has been renamed or is a Private channel, you can always get the Url to the folder in SharePoint.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s