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 a 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 a 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 an Azure AD App and provide the necessary permission to call the 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 use advanced options to pass the required tenant ID, client ID, secret, etc.

Let us start building the solution,

Create an Azure AD APP and Provide the 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, and select Azure AD.

Azure AD

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

App Registrations

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

Register

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

 API Permissions

At the below options, select Graph API.

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 select the below permissions and Click on the Add permissions button.

 Teams Tab

Once permission is added, we should see the 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.

Grant Admin

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. 

Confirmation box

The next step is to create a client secret that will be used later, click on Certificates and Secrets from the left blade and click on New Client Secret.

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 will mask later if we move away from this page. 

Description

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.

Client ID

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 assign the default values.

Creating Power Automate

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 that the 2 steps below are only for getting the 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. 

 Initialize Team ID

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 want to add to the specific channel we just need to use an HTTP post call outside of the loop.

HTTP post call

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

 HTTP Action

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 the Power App URL. 

Keep a note on the [email protected] attribute - this is basically a type of teams app of the tab showing the web URL.

{
    "displayName": "Calendar Screen App",
    "[email protected]": "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 a call to Graph API is made via the required Azure AD authentication parameters.

Configure advanced 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.

 Parameters

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 an access token and then use it to call actually Graph API endpoint. 

Below is how the whole flow would look like,

 Graph API endpoint

Let us save it and run it. Once it has run successfully, we can see that a Tab is added to targeted Teams and their channels. 

 Run successfully

Conclusion

In this article, we have learned the below concept.

  • How to create and set up 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 a client ID and secret.
  • How to Add a Power App as Teams Tab using Power Automate.

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


Similar Articles