“I’d like to create a Teams private channel for each new project, can I automate with with a Power Automate flow?”
Teams private channels are a great place to share more sensitive information. Instead of giving access to everyone in a Team, you can select only some of the users. At the same time, it can also help you separate the information, e.g. per project. But creating such channel takes some effort – create it with a proper name, add the owners, add the members… Why not automate it? To create such channel automatically once a project is created in a system?
Use the Graph HTTP request action
In the past I wrote articles on adding and removing members from a private channel. However, these solutions require an application registered in Azure and premium Power Automate licences.
Now there’s another action to use the Teams API without these prerequisites – Send a Microsoft Graph HTTP request.
No need for premium license, no need for Azure app, many operations available directly. One of them is creation of a new Teams private channel.
Method: POST
Uri: https://graph.microsoft.com/v1.0/teams/<TeamId>/channels
Body:
{
"@odata.type": "#Microsoft.Graph.channel",
"membershipType": "private",
"displayName": "<channelName>",
"description": "<channelDescription>",
"members": [<array with channel owners/members>]
}
As you can see, there’re two placeholders additionally to the channel name and description. The first one is the TeamId in the Uri. Since you want to create a private channel, you must create it in a specific Team – hence the need for the team Id (= related M365 group id). You can get it using the ‘List teams’ or ‘List groups’ actions and extracting the id.
The second placeholder, the array with channel owners/members is more tricky. You can’t just list all the users by email addresses, you must create a whole object for each user.
{
"@odata.type": "#microsoft.graph.aadUserConversationMember",
"user@odata.bind": "https://graph.microsoft.com/v1.0/users('<userId>')",
"roles": [
"<member/owner>"
]
}
One user equals one such object in an array. If I want for example add myself to the private channel, I’ll get my user profile to extract my user id and add myself as the owner.
You can see also that I replace the ‘@odata.type’ string with an expression:
string('@odata.type')
It’s because Power Automate designer sometimes complains that the object is invalid when a property starts with @.
Once I append all the users, including their roles, into an array variable, I can use it to create the Teams private channel.
IMPORTANT! at the time of this article the Teams action above can’t add channel members later. It can add members/owners only during the creation, to manage memberships in existing channels you must follow the more complex path (add / remove).
Summary
As you can see, Power Automate can help you even in preparation phases of a project, e.g. when you need to create a Teams private channel for better cooperation. The Graph HTTP request action even makes it much easier – you don’t need anything setup in Azure, no premium licenses, all you need is the proper format of the request.
Get the Id of the Team where you want to create the channel, prepare an array with members/owners of that channel, and you’re good to go. Just keep in mind that each Team can have a maximum of 30 private channels.
Hello,
Thanks for this article, It’s exactly what I was lookinf for.
Just a comment, form my sinde I receving an error message when I validate my flow due to variable function issued in the POST action : “The template function ‘variables’ is not expected at this location.”
Can you plesae describe what you put on your Body field for this ?
Hello Xavier,
that’s a reference to the variable where I store all the users that should be added as shown on the 2nd image.