Use Power Automate to get a MS Teams SharePoint URL

This post is inspired by a question I received on LinkedIn on how to copy files to a project based Teams team using Power Automate at the time of provisioning. This Flow can provide one of the building blocks for that larger solution.

Completed Flow

This Flow requires a Graph API connection. I outline how to do this in the following blog post: Use MS Lists and Power Automate to provision Private Channels in Teams.

Create a new Flow from Power Automate > Create new > Scheduled from blank. Provide a Flow name, i.e. “Get WebURL for a Teams team” and click “Create”.

Power Automate > Create new > Scheduled from blank.

Create a new Initialize variable action. Using an Object variable will reduce the number of variable declarations within the Flow. Set Name to “varConnectInfo”, Type to “Object” and Value to:

{
   "varDirectoryID": "<Enter your Directory ID>",
   "varApplicationID": "<Enter your Application ID>",
   "varSecret": "<Enter your Client Secret Value>"
}
Initialize variable action

Create a new Compose action. Set Inputs to variable “varConnectInfo”.

Compose action

Insert a new Microsoft Teams – Get a team step. Set Team to a team of your choosing. In my example I am using a Team called “NY Demo”. This could easily be switched with a dynamic value from a previous action like a Microsoft Teams Create a team action.

Microsoft Teams Get a team step

Add a Azure AD – Get group step and set Group Id to “id” from the previous Get a team step.

Get group

Insert a new HTTP action and set:

  • Method to “GET”
  • URI to https://graph.microsoft.com/v1.0/groups/<Id>/drive where <Id> is from the previous Azure AD – Get group step
  • Authentication to “Active Directory OAuth”
  • Tenant to “variables(‘varConnectInfo’)?[‘varDirectoryID’]”
  • Audience to https://graph.microsoft.com
  • Client ID to “variables(‘varConnectInfo’)?[‘varApplicationID’]”
  • Credential Type to “Secret”
  • Secret to “variables(‘varConnectInfo’)?[‘varSecret’]”

Save and test the Flow. Copy the output from the HTTP step.

Output from the HTTP step

Add a Parse JSON step, set:

  • Content to “Body” from the previous HTTP step
  • Click “Generate from sample” and past in the copied output from the HTTP step
Parse JSON step

Insert a new Initialize variable and set Name to “varWebURL”, Type to “String” and Value to “webUrl” from the previous Parse JSON action.

Save and test your Flow. If all goes well the “varWebURL” will store the web URL to our Teams team underlying SharePoint site and default drive (aka Document Library). Copying files at this point should be fairly simply using the SharePoint – Copy files action. Don’t forget to include the Teams channel folder name in the SharePoint address, i.e. “/General”.

"varWebURL" will store the web URL to our Teams team underlying SharePoint site and default drive (aka Document Library).

I like this pattern for centralized deployment and management of Teams for projects, committees and other types of working groups where control and consistency is key.

Thanks for reading!

NY

8 thoughts on “Use Power Automate to get a MS Teams SharePoint URL

  1. Very helpful!

    There is an easier way for Office Graph. You can use a connector called “HTTP with Azure AD > Invoke an HTTP Request” to call the Office API using your AD credentials.

    Second, I believe the Group Id GUID is always equal to the Team Id GUID? I’m not 100% confident in this, but might save a step by simply getting the GUID after looking up the Team?

    There are also other “API” connectors that use AD, for example SharePoint also has one.

    Like

    1. Hi Joel,

      The HTTP with Azure AD action is new to me and I will try it out next time I am doing Graph API work in Flow. I just checked the Group ID and Team ID and they are same.

      Thanks for the feedback and thanks for reading!

      NY

      #AlwaysLearning

      Like

    1. Hey chanceofflight,

      Sorry for the delayed response. Ensure that the single quote are straight single quotes:

      Bad = variables(‘varConnectInfo’)?[‘varDirectoryID’]
      Good = variables(‘varConnectInfo’)?[‘varDirectoryID’]

      I hope that helps and thanks for reading!

      NY

      Like

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 )

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