How to create Microsoft Teams private channels using Power Automate and the ‘Send a Microsoft Graph HTTP request’ action

Using the standard Power Automate actions for Microsoft Teams we can only create a standard channel, but by using Microsoft Graph with the new ‘Send a Microsoft Graph HTTP request’ action it’s possible to extend the standard actions similarly to my previous post, and create private channels in Microsoft Teams.

Microsoft Graph request format

To create a Microsoft Teams channel via Graph, you need to send a request body representing the channel object.

This object has a property named membershipType, which represents the type of the channel. This property can be set during creation only.

When creating a private channel as urgent, we need to set the membershipType of the channel as private.

Then we run a POST request against the team channels endpoint to create the channel, sending the request body using this format.

Creating a private channel

To create a private channel we can run a POST request against the following graph endpoint:

https://graph.microsoft.com/v1.0/teams/{team-id}/channels

Sample body request (note that the ‘members’ array below contains one owner and a member, a member simply does not have the “owner” role in the roles array):

{
  "@odata.type": "#Microsoft.Graph.channel",
  "membershipType": "private",
  "displayName": "My Display Name",
  "description": "A private channel",
  "members": [
    {
      "@odata.type": "#microsoft.graph.aadUserConversationMember",
      "user@odata.bind": "https://graph.microsoft.com/v1.0/users('<GUID OF OWNER>')",
      "roles": [
        "owner"
      ]
    },
    {
      "@odata.type": "#microsoft.graph.aadUserConversationMember",
      "roles": [],
      "user@odata.bind": "https://graph.microsoft.com/v1.0/users('<GUID OF MEMBER>')"
    }
  ]
}

Notes:

  1. Any private channel member needs to be a team member, otherwise, the request will fail.
  2. If you create a private channel and don’t add your own user as owner or member, you won’t see it on the channels list of the team.

Sample usage in Power Automate

Below we create a private channel, and before creating it we dynamically get the owner and member using the Office 365 users connector actions:

Results

After running a flow with the action as above, you will get the channel properly created:

Limitations

Currently using this ‘Send a Graph HTTP request’ action it’s not possible to add members to existing channels:

Resources

Channel resource type – Microsoft Learn

Create channel – Microsoft Learn

4 comments

  1. My body content is being escaped and I don’t know how to fix.

    I can copy-paste what’s used here and replace the variable bits as required or just hand-type it in and every single double quote, when I look at Code View, is escaped as \” and every new line is escaped as \n.

    Which ends up with that action erroring out because the Body isn’t actually JSON as expected.

    How can I fix this?

  2. This information is very critical and timely for my automation project.
    Initially encounter some errors like bad request and missing content-type.
    But eventually manage to resolve them after analyzing the error messages.

    Thank you so much for your sharing.
    Greatly appreciated it.

Leave a Reply

Your email address will not be published. Required fields are marked *