Microsoft Officially does not support automated adding of the SharePoint app to a Microsoft Teams Team as a tab, but on a number of occasions showed that the SharePoint app outperforms other Teams apps as the Web Connector app or Document library app for embedding SharePoint pages and document library views.
Now the question is how to automate adding the SharePoint app to Teams Team as a new tab because there is a caveat specifically for document library pages.
Let's do a little reverse engineering to find out what the SharePoint app actually is.It turns out that the SharePoint app uses the same applications page as the Files tab in Teams, and the application page is hosted at this location: https://<tenant>.sharepoint.com/sites/<your_site>/_layouts/15/filebrowser.aspx.
So far, so good. What I did is add the SharePoint app manually to a Microsoft Teams Team and extract the tab configuration by using the CLI for Microsoft 365. Here is how it looks:
{
"id": "2de8e489-b925-49c2-b371-a94aef8f408a",
"displayName": "Shared Documents",
"webUrl": "https://your_tenant.sharepoint.com/sites/your_site/Shared Documents",
"configuration": {
"entityId": "sharepointtab_0.7914902334185134",
"contentUrl": "https://your_tenant.sharepoint.com/sites/your_site/_layouts/15/teamslogon.aspx?spfx=true&dest=https%3A%2F%2Fyour_tenant.sharepoint.com%2Fsites%2Fyour_site%2F_layouts%2F15%2Ffilebrowser.aspx%3Fapp%3Dteamsfile%26scenario%3DteamsPage%26theme%3D%7Btheme%7D%26fileBrowser%3D%7B%22sdk%22%3A%221.0%22%2C%20%22entry%22%3A%20%7B%22sharePoint%22%3A%7B%22byPath%22%3A%20%7B%22folder%22%3A%20%22%2Fsites%2Fyour_site%2FShared%20Documents%22%7D%7D%7D%7D",
"removeUrl": null,
"websiteUrl": "https://your_tenant.sharepoint.com/sites/your_site/Shared Documents/Forms/AllItems.aspx",
"dateAdded": "2023-05-15T11:13:46.613Z"
},
"teamsApp": {
"id": "2a527703-1f6f-4559-a332-d8a7d288cd88",
"externalId": null,
"displayName": "SharePoint",
"distributionMethod": "store"
},
"teamsAppTabId": "2a527703-1f6f-4559-a332-d8a7d288cd88"
}
So, important in this case is the contentUrl param, which seems to be set to get over login, then the user is being redirected to the filebrowser.aspx application page. Here is the prettified URL in the dest param or the contentUrl entity:
https://your_tenant.sharepoint.com/sites/your_site/_layouts/15/teamslogon.aspx?spfx=true&dest=https://your_tenant.sharepoint.com/sites/your_site/_layouts/15/filebrowser.aspx?app=teamsfile&scenario=teamsPage&theme=default&fileBrowser={"sdk":"1.0", "entry": {"sharePoint":{"byPath": {"folder": "https://your_tenant.sharepoint.com/sites/your_site/Shared Documents"}}}}
Few interesting things to discover about the filebrowser.aspx application page is that it behaves differently based on the query string parameters sent to the page. We have the app, scenario, theme and fileBrowser params. A bit more reverse engineering shows that the app param has the following values TeamsList, TeamsPage, TeamsFile and SP, which causes the filebrowser page to behave differently. The scenario param has the following values onedrivefiles, teamspage, portals and ChannelFiles. Again it changes the screen views depending on switching to one of the scenario param values. The theme has two values, default and currentTheme, where the currentTheme is a dynamic variable, so to be on the safe side, I would use 'default' as the value.
Now, seems that the proper way to automatically deploy a SharePoint app is by setting the right URL with all its patterns to for the contentURL.
https://<tenant>.sharepoint.com/sites/<your_site>/_layouts/15/teamslogon.aspx?spfx=true&dest=https://<tenant>.sharepoint.com /sites/<your_site>/_layouts/15/filebrowser.aspx?app=teamsfile&scenario=teamsPage&theme=default&fileBrowser={"sdk":"1.0", "entry": {"sharePoint":{"byPath": {"folder": https://<tenant>.sharepoint.com/sites/<your_site>/Shared Documents}}}}'
I found that the best outcome is when I use app=teamsfile&scenario=teamsPage&theme=default setup. Everything else has weird behaviour in the Teams desktop client.
So I can now use the CLI for Microsoft 365 to automate the creation of SharePoint app tabs for document library views. Here is an example. Open Powershell command line and run teams tab add:
PS C:\Users\velin.georgiev> m365 teams tab add -i 287104db-7cf7-413c-ac33-e3cf1829704e -c 19:3U8qYosuL7dNtRcUe4xpAJ-zVzmp-GPtraKLNoEWJHk1@thread.tacv2 --appId 2a527703-1f6f-4559-a332-d8a7d288cd88 --appName 'Velin Test 2' --contentUrl 'https://y2zh0.sharepoint.com/sites/y2zh0/_layouts/15/teamslogon.aspx?spfx=true&dest=https://y2zh0.sharepoint.com/sites/y2zh0/_layouts/15/filebrowser.aspx?app=teamsfile&scenario=teamsPage&theme=default&fileBrowser={"sdk":"1.0", "entry": {"sharePoint":{"byPath": {"folder": "https://y2zh0.sharepoint.com/sites/y2zh0/y2zh20%20DMS"}}}}' --websiteUrl 'https://y2zh0.sharepoint.com/sites/y2zh0/y2zh20%20DMS'
Result is returned to me:
{
"id": "7309036d-61d6-464e-beac-cf15c090b3b0",
"displayName": "Velin Test 2",
"webUrl": "https://teams.microsoft.com/l/channel/19%3a3U8qYosuL7dNtRcUe4xpAJ-zVzmp-GPtraKLNoEWJHk1%40thread.tacv2/tab%3a%3a7309036d-61d6-464e-beac-cf15c090b3b0?webUrl=https%3a%2f%2fy2zh0.sharepoint.com%2fsites%2fy2zh0%2fy2zh20%2520DMS&label=Velin+Test+2&groupId=287104db-7cf7-413c-ac33-e3cf1829704e&tenantId=224b4d39-fd4d-4cc7-9718-3e71361e062e",
"configuration": {
"entityId": null,
"contentUrl": "https://y2zh0.sharepoint.com/sites/y2zh0/_layouts/15/teamslogon.aspx?spfx=true&dest=https://y2zh0.sharepoint.com/sites/y2zh0/_layouts/15/filebrowser.aspx?app=teamsfile&scenario=teamsPage&theme=default&fileBrowser={sdk:1.0, entry: {sharePoint:{byPath: {folder: https://y2zh0.sharepoint.com/sites/y2zh0/y2zh20%20DMS}}}}",
"removeUrl": null,
"websiteUrl": "https://y2zh0.sharepoint.com/sites/y2zh0/y2zh20%20DMS"
}
}
Provisioning SharePoint pages as a SharePoint app also has benefits. The syntax for automating this is simpler, and some might not be needed. For example:
Command:
PS C:\Users\velin.georgiev> m365 teams tab add -i 287104db-7cf7-413c-ac33-e3cf1829704e -c 19:3U8qYosuL7dNtRcUe4xpAJ-zVzmp-GPtraKLNoEWJHk1@thread.tacv2 --appId 2a527703-1f6f-4559-a332-d8a7d288cd88 --appName 'Velin Test 3' --contentUrl 'https://y2zh0.sharepoint.com/sites/y2zh0/_layouts/15/teamslogon.aspx?spfx=true&dest=https://y2zh0.sharepoint.com/sites/y2zh0' --websiteUrl 'https://y2zh0.sharepoint.com/sites/y2zh0'
Result:
{
"id": "e7860083-81dd-4140-9b00-a5420590c79d",
"displayName": "Velin Test 3",
"webUrl": "https://teams.microsoft.com/l/channel/19%3a3U8qYosuL7dNtRcUe4xpAJ-zVzmp-GPtraKLNoEWJHk1%40thread.tacv2/tab%3a%3ae7860083-81dd-4140-9b00-a5420590c79d?webUrl=https%3a%2f%2fy2zh0.sharepoint.com%2fsites%2fy2zh0&label=Velin+Test+3&groupId=287104db-7cf7-413c-ac33-e3cf1829704e&tenantId=224b4d39-fd4d-4cc7-9718-3e71361e062e",
"configuration": {
"entityId": null,
"contentUrl": "https://y2zh0.sharepoint.com/sites/y2zh0/_layouts/15/teamslogon.aspx?spfx=true&dest=https://y2zh0.sharepoint.com/sites/y2zh0",
"removeUrl": null,
"websiteUrl": "https://y2zh0.sharepoint.com/sites/y2zh0"
}
}
Command:
PS C:\Users\velin.georgiev> m365 teams tab add -i 287104db-7cf7-413c-ac33-e3cf1829704e -c 19:3U8qYosuL7dNtRcUe4xpAJ-zVzmp-GPtraKLNoEWJHk1@thread.tacv2 --appId 2a527703-1f6f-4559-a332-d8a7d288cd88 --appName 'Velin Test 4' --contentUrl 'https://y2zh0.sharepoint.com/sites/y2zh0/_layouts/15/teamslogon.aspx?spfx=true&dest=https://y2zh0.sharepoint.com/sites/y2zh0?path=/sites/y2zh0' --websiteUrl 'https://y2zh0.sharepoint.com/sites/y2zh0?path=/sites/y2zh0'
Result:
{
"id": "716cf71b-8a57-4321-a370-037e06306fac",
"displayName": "Velin Test 4",
"webUrl": "https://teams.microsoft.com/l/channel/19%3a3U8qYosuL7dNtRcUe4xpAJ-zVzmp-GPtraKLNoEWJHk1%40thread.tacv2/tab%3a%3a716cf71b-8a57-4321-a370-037e06306fac?webUrl=https%3a%2f%2fy2zh0.sharepoint.com%2fsites%2fy2zh0%3fpath%3d%2fsites%2fy2zh0&label=Velin+Test+4&groupId=287104db-7cf7-413c-ac33-e3cf1829704e&tenantId=224b4d39-fd4d-4cc7-9718-3e71361e062e",
"configuration": {
"entityId": null,
"contentUrl": "https://y2zh0.sharepoint.com/sites/y2zh0/_layouts/15/teamslogon.aspx?spfx=true&dest=https://y2zh0.sharepoint.com/sites/y2zh0?path=/sites/y2zh0",
"removeUrl": null,
"websiteUrl": "https://y2zh0.sharepoint.com/sites/y2zh0?path=/sites/y2zh0"
}
}