Adding Power App To Teams Tab Using Power Automate

Scenario

Consider you have teams automation in place and wanted to add Power App to Microsoft Teams Channel as Tab. This can be useful in a way when teams are automatically created and we need to add a tab using automation, in this case, we would be using Power Apps but the same concept can be used to add a Tab with any URL. 

General notes about solution for our understanding,

  • We would be using Team Graph API to add a tab - below endpoint needs to be called - https://docs.microsoft.com/en-us/graph/api/channel-post-tabs?view=graph-rest-1.0
  • If we look at the documentation, it would need targeted team Id and Channel Id, so this can be obtained by querying based on a team name or channel name. Or based on your scenario, this can be retrieved from any data source. For the sake of this example, we will use a hardcoded team Id and Channel Id
  • We need to create Azure AD App and provide the necessary permission to call below endpoint,
    POST /teams/{team-id}/channels/{channel-id}/tabs
  • To call any Graph API from Power Automate, there are several ways, we will use HTTP POST action to make calls and by using advanced options to pass required tenant id, client id, secret, etc.

Let us start building the solution,

Create Azure AD APP and Provide necessary Permissions

Pre-requisite

To do this, we need to have access to Azure AD and also admin access to provide consent because we would be calling the targeted endpoint using Application Permissions to avoid sending the user's credentials.

Go to portal.azure.com, select Azure AD.

Once we are on the below page, select App Registrations from the left side. Select New Registration from the top.

On the below page, provide the name of the AD app, select the first option which says to access this API in this tenant only, and click on Register,

Once it is created successfully, we should see the below page. Click on API Permissions and Add a Permission.

At the below options, select Graph API.

In our case, as I said we will be using application permission so choose Application permission.

Search for TeamsTab in the search box and select the below permissions and Click on Add permissions button.

Once permission is added, we should see below screen and a warning for each permission saying that Not granted for .....We need to provide admin consent so that it allows to use of this client app to make calls to Graph API based on targeted permissions. Click on the Grant Admin content button as marked below.

We will be shown a confirmation box and then we should see below tick marks with a message that consent is granted for each permission. 

The next step is to create a client secret which will use later, click on Certificates and secrets from the left blade, Click on New Client Secret

Provide a description and expiration date based on your preference and click on Add. Once it is added, we can see the secret value like below, we need to make sure to copy it somewhere at this point in time else it would mask later if we move away from this page. 

The next step is to get a copy client Id, from the left blade, click on Overview, and note the Client Id and Tenant Id as in the below screenshot.

Now we are ready with setup from the Azure AD side to call the Graph API and we have the required information which we will use in Power Automate.

Creating Power Automate

For the sake of simplicity, I will use manually triggered flow but you can do it based on your preference. First, we would need to make sure we have the required actions to initialize variables to store required values. The below screenshot will give you an idea of the 4 variables that we need and assigning the default values.

The next action, in this case, is to initialize Team Id and Channel ID. In this example, I am using the default action Get Team and its Channel and use it inside the loop to add this Table to all the channels in that particular Team. Please note below the 2 steps below is only for getting Targeted Team Id and Channel Id. So, in this case, it will always add to this team, but ideally, in a real-world scenario, this would be dynamic and should be populated differently. 

Next, add an action that applies for each(again, in this example we are adding this tab to every channel found within the team so we are using a loop) but if you wanted to add to the specific channel we just need to use an HTTP post call outside of the loop.

Adding PowerApp to Teams Tab using Power Automate

Inside Apply for each add HTTP Action and configure it like below,

Request URL

https://graph.microsoft.com/beta/teams/@{outputs('Get_a_team')?['body/id']}/channels/@{items('Apply_to_each')?['id']}/tabs

Below is a body that we have used in our case, the dynamic value here is Power App URL. 

Keep a note on the teamsApp@odata.bind attribute - this is basically a type of teams app of the tab showing web URL.

{
    "displayName": "Calendar Screen App",
    "teamsApp@odata.bind": "https://graph.microsoft.com/beta/appCatalogs/teamsApps/com.microsoft.teamspace.tab.web",
    "teamsAppId": "com.microsoft.teamspace.tab.web",
    "configuration": {
        "entityId": "2DCA2E6C7A10415CAF6B8AB6661B3154",
        "contentUrl": "@{variables('PowerAppURL')}",
        "websiteUrl": "@{variables('PowerAppURL')}",
        "removeUrl": ""
    }
}

Click on the Advanced option, next thing is we have set up authentication so that call to Graph API is made via required Azure AD authentication parameters.

Configure advance options like below.

Choose Authentication to Active Directory OAuth.

Choose Credential Type to Secret.

Enter all the parameters as in the below screenshot by selecting targeted variables.

This is the easiest and smartest way to get the authentication because by using a technique we don't have to take care of getting access token and then use it to call actually Graph API endpoint. 

Below is how whole flow would look like,

Let us save it and run it. Once it has run successfully, we could see that a Tab is added to targeted Teams and its channel. 

Adding PowerApp to Teams Tab using Power Automate

Conclusion

In this article, we have learned the below concept,

  • How to create and setup Azure AD APP and provide required permission to call Graph API.
  • How to Call Graph API End Point using HTTP Post action(premium) by using client id and secret.
  • How to Add a Power App as Teams Tab using Power Automate.

Hope this helped...Happy low coding..!!!